perl

How can I read the output from external commands in real time in Perl?

I have a few bash scripts I run, but they can take several hours to finish, during which time they spew out download speeds, ETAs and similar information. I need to capture this information in perl, but I am running into a problem, I cannot read the output line by line(unless I'm missing something). Any help working this out? EDIT: to ...

Is there an easy way to localise (preserve) all "magic variables" like $1, $& etc.?

I know that in a subroutine in Perl, it's a very good idea to preserve the "default variable" $_ with local before doing anything with it, in case the caller is using it, e.g.: sub f() { local $_; # Ensure $_ is restored on dynamic scope exit while (<$somefile>) { # Clobbers $_, but that's OK -- it will be restored...

How can I compile my Perl script so it can be executed on systems without perl installed?

I have a .pl file and I want to execute that file in any system even though perl is not installed. How can i achieve it? Can any one let me know with some good examples to do that? ...

Is my Rose::DB::Object compile-time too slow?

Hi folks, I'm planning to move from Class::DBI to Rose::DB::Object due to its nice structure and the jargon that RDBO is faster compares to CDBI and DBIC. However on my machine (linux 2.6.9-89, perl 5.8.9) RDBO compiled time is much slower than CDBI: $ time perl -MClass::DBI -e0 real 0m0.233s user 0m0.208s sys 0m0.024s $ t...

How can I add an image at a specific X, Y location using Perl's PDF::API2?

I'm using Perl's PDF::API2 module to create a PDF document and I need to add an PNG image at a specific X,Y location on the page. How do I do this? ...

How can I process a binary file of fixed length records with no line breaks in between?

Hi, I have a text file that's composed of fixed length records but all in one line with no line breaks in between. What's the best way to process it in Perl? Thanks! ...

How can I use Perl's XML::LibXML to extract an attribute in a tag?

I have an XML file <PARENT > <TAG string1="asdf" string2="asdf" > </TAG > </PARENT> I want to extract the string2 value here.. and also I want to set it to a new value.. How to do that? ...

How can I reference a hash with a variable name?

I have three hashes named %hash1, %hash2, %hash3. I need to reference each hash by variable and am not sure how to do it. #!/usr/bin/perl # Hashes %hash1, %hash2, %hash3 are populated with data. @hashes = qw(hash1 hash2 hash3); foreach $hash(@hashes){ foreach $key(keys $$hash){ .. Do something with the hash key and value...

How can I join two hashes in Perl without using a loop?

How do I append hash a to hash b in Perl without using a loop? ...

Generating a graph with multiple (sets of multiple sets of multiple) X-axis data sets

I am looking for a way to generate a graph with multiple sets of data on the X-axis, each of which is divided into multiple sets of multiple sets. I basically want to take this graph and place similar graphs side by side with it. I am trying to graph the build a graph of the duration (Y-axis) of the same jobs (0-3) with different confi...

How can my WxPerl application ignore keypresses while a method runs?

I have an application that waits for the user to press a key and then executes a long running method that periodically updates the GUI. sub keypress{ my $self = shift; my $event = shift; if ($event->GetKeyCode() == WXK_F12){ $self->doStuff(); }else{ $event -> Skip(0); } } I would like to have the application ignore...

In Perl, how can I release memory to the operating system?

I am having some problems with memory in Perl. When I fill up a big hash, I can not get the memory to be released back to the OS. When I do the same with a scalar and use undef, it will give the memory back to the OS. Here is a test program I wrote. #!/usr/bin/perl ###### Memory test ###### ## Use Commands use Number::Bytes::Human qw(...

Programmatically extract data from an Excel spreadsheet.

Is there a simple way, using some common Unix scripting language (Perl/Python/Ruby) or command line utility, to convert an Excel Spreadsheet file to CSV? Specifically, this one: http://www.econ.yale.edu/~shiller/data/ie_data.xls And specifically the third sheet of that spreadsheet (the first two being charts). ...

Short script, long module or long script, short module?

I was just wondering what is best for performance when making a web service in Perl. Is it best to have as short as possible .pl script and put as much code as possible in a module that is used by the .pl script, or doesn't it impact performance if i don't use a module at all? I am using mod_perl on a CentOS Linux box with perl 5.8.8....

Linux command to replace string in LARGE file with another string

I have a huge SQL file that gets executed on the server. The dump is from my machine and in it there are a few settings relating to my machine. So basically, I want every occurance of "c://temp" to be replace by "//home//some//blah" How can this be done from the command line? ...

How can I code a factory in Perl and Moose?

Is there a simpler or better (=>easier to maintain) way to use Perl and Moose to instantiate classes based on incoming data? The following code is a stripped down sample from a project I'm working on. package FooBar; use Moose; has 'SUBCLASS' =>('isa'=>'Str',required=>'1',is=>'ro'); has 'MSG' =>('isa'=>'Str',required=>'1',is=>'ro'); s...

Can I write ISAPI filters in Perl?

I need to write an ISAPI filter for IIS 6.0 to rewrite ugly URLs into SEO-friendly URLs. Because of the need for string parsing and regular expressions, I'd prefer to use Perl to do this. There is a module for IIS called (ingeniously) Perl for IIS, but I'd rather not use that because it's an ISAPI extension itself (running in a DLL), so ...

Why do I get "undefined reference" errors when I compile my XS with Perl 5.10?

Hi I have a C++ object that I am converting to Perl using Perl XS. This process works fine with Perl 5.8.5 and 5.8.7. But as soon as I try to use Perl 5.10.0, I run into a lot of compile errors. Most of them are along these lines: undefined reference to 'PL_stack_max' undefined reference to 'PL_stack_sp' undefined reference to 'Perl_...

Is there a Perl equivalent for String.scan found in Ruby?

I want to do this in Perl: >> "foo bar baz".scan /(\w+)/ => [["foo"], ["bar"], ["baz"]] Any suggestions? ...

What does the "s!" operator in Perl do?

I have this Perl snippet from a script that I am translating into Python. I have no idea what the "s!" operator is doing; some sort of regex substitution. Unfortunately searching Google or Stackoverflow for operators like that doesn't yield many helpful results. $var =~ s!<foo>.+?</foo>!!; $var =~ s!;!/!g; What is each line doing? I...