perl

Would installing Perl 5.8.x or 5.10.x make a big impact on how my code runs if it was developed in 5.6.x?

What are the impacts (If any) by developing code in Perl 5.6.1 but running the code in Perl 5.8.x or 5.10.x? I'm using these modules: (For Linux) HTTP::Request HTTP::Response LWP::UserAgent Unicode::String XML::DOM DateTime::Format::DateManip (For Windows) Unicode-String XML-DOM DateTime-Format-DateManip (Haven't installed this yet ...

Perl: Define hash with reference to the same hash, $this->{key}?

How would I create a hash like the follow: my %hash = (key1=>"Something", key2=>$hash{key1} . "Else"); Can this not be done while when I declare the hash? So far, the only thing I came up with was: my %hash = (key1=>"Something"); $hash{key2} = $hash{key1} . "Else"; ...

How do I forward the current Asterisk call in AGI using Perl?

I have an asterisk-based PBX, and I have been able to successfully run an AGI script from the web control panel of the PBX. Because I am calling AGI from Perl (neither of which I know, yet)... asterisk commands look like this: print "SET CALLERID $newcid \"\"\n"; So far, I don't expect to need to do any database lookups, etc. ...

How can I loop through files in a directory in Perl?

Possible Duplicate: How can I list all of the files in a directory with Perl? I want to loop through a few hundred files that are all contained in the same directory. How would I do this in Perl? ...

How can I format a timestamp in Perl?

I would like to get this timestamps formatting: 01/13/2010 20:42:03 - - Where it's always 2 digits for the number except for the year, where it's 4 digits. And it's based on a 24-hour clock. How can I do this in Perl? I prefer native functions. ...

How do I access random element in a Perl DBM hash?

I have a Perl DBM hash containing a list of URLs that I want to pick randomly from to load balance spidering sites. As a result I want to pick a key at random, or select the nth element (so I can randomise n). I'm aware this goes against the concept of a hash, but is this possible? NOTE: missed a valuable point that hash size will be ...

Perl on MacOS X 10.6.2: GDBM_File missing, how to install or work around?

When I need a Perl module, I typically use CPAN. It works fine. But not this time. I want to use MARC::Charset, but this one uses GDBM_File, and I can't seem to install GDBM_File from CPAN. CPAN finds it all right, but trying to install it, it starts installing the full Perl 5.10.1 distribution. MARC::Charset is a rather old module, s...

What is the cause for “panic: free from wrong pool during global destruction.” in Term::ReadLine::Gnu?

Hello stackers, in https://rt.cpan.org/Ticket/Display.html?id=37194#txn-641389 I reopened a bug concerning a Perl crash in conjunction with the libreadline XS bindings. I attached the necessary debug information, but until now there has been no acknowledgement from the maintainer. I want this finally fixed; it's a major inconvenience to...

What's a good way to refactor a monster Perl module into submodules?

I have a Perl module for a project. I have maybe a dozen programs hanging off it and a lot of it is garbage. I hadn't spent much close personal time with DBI before, so that part is fixable, but the big thing is that it is big. Literally 2KLOCs. It would be easy to break up this function (let's call it Dumb.pm) into separate modules ( ...

How can I debug a possible memory leak in a Perl CGI script?

I have a legacy Perl CGI page running on Apache that processes a large Excel spreadsheet worth of data, adding to the database as necessary. It gets processed in groups of data, and each group of data gets sent to the database. After each call to the database, my system's available memory decreases significantly to the point where there...

How do I escape special chars in a string I interpolate into a Perl regex?

I have a string which may hold special characters like: $, (, @, #, etc. I need to be able to perform regular expressions on that string. Right now if my string has any of these characters the regex seems to break since these are reserved characters for regex. Does anybody knows a good subroutine that would escape nicely any of these c...

How can I use Smart::Comments in a module I load without changing its source?

How can I specify that Smart::Comments be loaded for my original script, as well as for any of the modules it directly loads. However, since it is a source-filter, it would probably wreck havoc if applied to every module loaded by every other loaded module. For example, my script includes use Neu::Image; I would like to load Smart:...

Which Perl XML parser can add data to particular nodes?

I need to add a few lines in an XML file at a particular node, in Perl. So, I need to search for a particular node and then add those lines. Which parser would you recommend for this? ...

Are there flaws in my web session handling process?

Okay so the way this works is the user authenticates via web form and generates a session ID as so: sub session_open { my $sid; my $user = shift; if ( open(SEMA, "> ../sema/sess") ) { flock SEMA, LOCK_EX; do { $sid = generate_session_id(); } while ( -d "$SDIR/$sid" )...

Importing in hierarchical Perl modules into the local namespace

Situation: I have a module Foo::Quux::Bar, living in ./Bar.pm. I need to be able to unit test Bar. However, it is not advantageous due to circumstances beyond my control to set up a Foo/Quux directory structure. So what I'd like to do is have some sort of unit_test_use routine that lets me grab Bar.pm and move/copy its functions into ...

How can I safely use regexes from user input?

My (Perl-based) application needs to let users input regular expressions, to match various strings behind the scenes. My plan so far has been to take the string and wrap it in something like $regex = eval { qr/$text/ }; if (my $error = $@) { # mangle $error to extract user-facing message ($text having been stripped of newlines ahe...

Is the 'my $x if 0' trick usable for static variable creation for Perls before 5.10?

In Perl before 5.10 there is no "state" declaration. I've come across an example of creating static variables in these Perls: my $x if 0. The if 0 conditional makes the variable act like a static variable: use strict; use warnings; add() for 1..7; sub add { my @arr = () if 0; push @arr, '+'; print @arr, "\n"; } prints: ...

How can I search and replace a match a specific number of times in a string in Perl?

How can I search and replace a match with specific number of times using s///;. For example: $string="abcabdaaa"; I want to replace a with i in $string n times. How can I do that? n is an integer provided by user. ...

Is there a WYSIWYG Perl Pod editor?

Is there an easy to use "what-you-see-is-what-you-get" editor for Pod available? I'm not that used to the Pod syntax yet so having the option of writing the Pod and immediatly see what the output would look like will help a lot. Ideally this editor would have some kind of "code-completion" to help with the correct syntax. Is there an ...

How can I handle packed data from Perl/PHP in C++?

I got a problem implementing a PHP programm in C++. It is about the PHP/Perl function unpack. I don't know how to do the follwing in C++ (no problem in reading a file... but how do i unpack("C*") the read contents). <?php $file = fopen("bitmaskt.dat", "rb"); //create the data stream $matrix_x = unpack("C*", fread($file, 286));...