perl

Why can't I remove this empty directory in Perl?

Hi there, I am converting a linux script from http://www.perlmonks.org/index.pl?node_id=217166 specifically this: #!/usr/bin/perl -w use strict; use Getopt::Std; use File::Find; @ARGV > 0 and getopts('a:', \my %opt) or die << "USAGE"; # Deletes any old files from the directory tree(s) given and # removes empty directories en passant. ...

How can I combine hashes in Perl?

What is the best way to combine both hashes into %hash1? I always know that %hash2 and %hash1 always have unique keys. I would also prefer a single line of code if possible. $hash1{'1'} = 'red'; $hash1{'2'} = 'blue'; $hash2{'3'} = 'green'; $hash2{'4'} = 'yellow'; ...

How do I set LC_ALL and LANG under IIS?

I am trying to run some Perl CGI scripts under IIS. I get the following message : CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LC_ALL = (unset), LAN...

How do I tell CPAN.pm where to get modules?

Here is the complete install command to CPAN and the output: sudo perl -MCPAN -e "install Bundle::CPAN" CPAN: Storable loaded ok (v2.13) Going to read /home/delgreco/.cpan/Metadata Database was generated on Mon, 08 Dec 2008 03:27:10 GMT CPAN: LWP::UserAgent loaded ok (v2.033) CPAN: Time::HiRes loaded ok (v1.55) CPAN: YAML loaded ok (v...

How do I replace a set of words in a file with another set in Perl?

My requirement is to replace a set of words in a given text file with a second set of words, which might be given from the command line or another file. Wanting to use Perl to do this, as the rest of my code is also in Perl. So, if I have the following: server name="${server1}" host="abc.com" server name="${server2}" host="webcs.com" s...

How can I debug the source of this error in XML::GDOME?

Hi there, I'm using GDOME.pm and in my script I have this line: my $doc = XML::GDOME->createDocument("","",""); I can't for the life of me figure out why it's coming out with this error: NAMESPACE_ERR at /usr/lib/perl5/site_perl/5.6.1/i586-linux/XML/GDOME.pm line 103. which basically points to: sub createDocument { my $class = ...

How can I prevent Windows from catching my Perl exceptions?

I have this Perl software that is supposed to run 24/7. It keeps open a connection to an IMAP server, checks for new mail and then classifies new messages. Now I have a user that is hibernating his XP laptop every once in a while. When this happens, the connection to the server fails and an exception is triggered. The calling code usual...

How do I pass pointers to a DLL using Win32:API?

Hi, I am trying to passing in 3 pointers to a DLL function. I have: { $code=1; $len=100; $str=" " x $len; $function = new Win32::API(DLLNAME,'dllfunction','PPP','V'); $function->Call($code,$str,$len); } The DLL is defined as void dllfunction(int* a, char* str, int* len); The DLL will modify all the variables pointed by the three ...

Is there a CPAN module to parse nested parentheses?

Is there a CPAN module that can read a string like this: "[[<asdf>, <foo>], (abc, def, ghi), ({'jkl'})]" ...and parse it into some sort of tree structure that's easy to walk and pretty-print? ...

How can I set Perl's inclusion path for modules for a CGI script?

Hello! I’ve got several Perl modules installed on my hosting machine in ~/perl, how do I add them to Perl module path? Setting PERL5LIB or unshifting the paths to @INC surely works, but the environment variable does not help when running as a CGI script and the @INC way is not very portable. Is there a better way? This has to be a common...

Why can't my Java program read Perl's STDERR?

Hi, We have a Perl program to validate XML which is invoked from a Java program. It is not able to write to standard error and hanging in the print location. Perl is writing to STDERR and a java program is reading the STDERR using getErrorStream() function. But the Perl program is hanging to write to STDERR. I suspect Java function is...

How can I print source line number in Perl?

Is it possible to get the current source line number in Perl? The equivalent in C++ is __LINE__. ...

How can I override hard-coded configuration in my Perl program?

I have a Perl script that sets up variables near the top for directories and files that it will use. It also requires a few variables to be set as command-line arguments. Example: use Getopt::Long; my ($mount_point, $sub_dir, $database_name, $database_schema); # Populate variables from the command line: GetOptions( 'mount_point=s'...

How can I reformat messages in an mbox file with bash or Perl?

Hello, I have a huge mbox file, with maybe 500 emails in it. It looks like the following: From [email protected] Fri Aug 12 09:34:09 2005 Message-ID: <[email protected]> Date: Fri, 12 Aug 2005 09:34:09 +0900 From: me <[email protected]> User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 ...

How do I find the module dependencies of my Perl script?

I want another developer to run a Perl script I have written. The script uses many CPAN modules that have to be installed before the script can be run. Is it possible to make the script (or the perl binary) to dump a list of all the missing modules? Perl prints out the missing modules’ names when I attempt to run the script, but this is ...

How can I handle multiple sockets within a Perl daemon with large memory usage?

I have created a client-server program with Perl using IO::Socket::INET. I access server through CGI based site. My server program will run as daemon and will accept multiple simultaneous connections. My server process consumes about 100MB of memory space (9 large arrays, many arrays...). I want these hashes to reside in memory and shar...

How do I skip to a specific input line in Perl?

I want to skip to the first line that contains "include". <> until /include/; Why does this not work? ...

How do I serve an image from the cgi directory under Tomcat?

I have configured Tomcat 6 to serve Perl CGI scripts. That part is well documented and works ok for me. But, when a browser requests an image from this CGI dir, Tomcat's CGI servlet refuses to serve the image, displaying instead merely the url of the image. I believe this is a security feature to prevent users from seeing the contents ...

How can I pass command-line arguments to a Perl program?

I'm working on a Perl script. First time in more than a decade. Really. How can I pass command line parameters to it? Example: script.pl "string1" "string2" ...

How can I extract or change links in HTML with Perl?

I have this input text: <html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><table cellspacing="0" cellpadding="0" border="0" align="center" width="603"> <tbody><tr> <td><table cellspacing="0" cellpadding="0" border="0" width="603"> <tbody><tr> <td width="314"><img height="61" ...