perl

What are the advantages of rsh versus Perl's Expect.pm?

I have a Perl Expect.pm script that does some moderately complex stuff like packaging applications, deploying the application, checking for logs, etc. on multiple remote unix hosts. My predecessor had written similar scripts using rsh. Is there a better approach between the two? Or should I use something all together different? I am...

How can I do I18N in HTML::Template[::Compiled] with gettext?

I'm currently trying to move a web project from a custom i18n system to gettext, however I'll need to prepare HTML::Template::Compiled templates for i18n too and don't know yet how to do it. My templates are stored in separate files, therefore I can't use Perl's string interpolation and I also would like to use gettext-typical _() syntax...

Will Perl upgrade break older version on Linux?

I upgrade perl from perl58 to perl588 on Suse Linux.It looks that even though the Config.pm exists for the older version the newer version installation breaks the older version.While the upgrade of Perl on other OSes like HP and AIX does not disturb the older version. For eg: The perl58 and perl588 versions are present in folder say "/us...

Is there a Perl module for parsing columnar text?

Let's say I have a tab-delimited text file that contains data arranged in columns (with headers). It is possible that different columns may be "stacked" into a "worksheet"-like arrangement, i.e. there is some divider (that may or may not be known ahead of time) that allows different columns to be arranged vertically. Is there a Perl m...

Compute numerical values from a space separated text file, within a range of lines

I have a file with the following values: for 3 threads: Average time taken for API1 is: 19097.7 nanoseconds. Average time taken for API2 is: 19173.1 nanoseconds. Average time taken for API2 is: 19777.7 nanoseconds. Average time taken for API2 is: 19243.1 nanoseconds. Average time taken for API1 is: 19737.7 nanoseconds. Average time take...

How can I skip lines when slurping a file in Perl?

How can I do this? open FILE, $somefile; foreach (<FILE>) { if (/some_regex/) { $want_the_next_line = <FILE>; $want_the_next_line_after_that = <FILE>; } } Know what I mean? I basically want to slurp in a bunch of lines in the middle of my foreach, instead of having to remember my state and check it every time I i...

How can I keep only the first five lines in a Perl scalar?

From any kind of scalar, what regex could I use to match the first five lines of it and discard the rest? ...

How can I read the error output of external commands in Perl?

As part of a larger Perl program, I am checking the outputs of "diff" commands of input files in a folder against reference files, where a blank output (a match) is a passing result, and any output from diff is a fail result. The issue is, if the target folder is short on the number of expected files, the exception diff throws doesn't c...

Recordset Iterating

I want to iterate through records returned from a MySQL database using Perl, but only ten records at a time. The reason is that the server component can only handle 10 items per request. For example: If the query returned 35 records then I have to send the data in 4 requests: Request # # of Records -------- ...

How can I kill Perl 'system' calls when the main script is killed?

Pervious answers to this questions have focused on forks: kill background process when shell script exit How to make child process die after parent exits? Are child processes created with fork() automatically killed when the parent is killed? For this question, I'm just asking about calls to the 'system' function. Say I have a scri...

Why does my command-line not run from cron?

I have a perl script (part of the XMLTV family of "grabbers", specifically tv_grab_oztivo). I can successfully run it like this: /sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml I use the full paths to everything to eliminate issues with the Working Directory. Permissions shouldn't be a problem. So, if I run it from the...

Apache2 mod_perl Last-Modified header ignored

I have a perl generated page. The contents of this page change every 30 minutes, so I'm setting $r->set_last_modified() to the time the contents last changed. That all works well and I can see the correct header arriving at my browser. When I refresh the page, I see my browser uses the correct "If-Modified-Since" header in the request ...

How do I count the characters, words, and lines in a file, using Perl?

What is a good/best way to count the number of characters, words, and lines of a text file using Perl (without using wc)? ...

Wrapping tabular data in HTML

I have some data with one row of headers and one or more rows of values that I want to display. Currently, I'm using an HTML table, but I've come across situations where I have so many columns, the table goes off the end of the screen. Or that some column names are so long (they're usually just a single word that have underscores as spac...

Why do regular expressions in Java and Perl act differently?

My understanding is that Java's implementation of regular expressions is based on Perl's. However, in the following example, if I execute the same regex with the same string, Java and Perl return different results. Here's the Java example: public class RegexTest { public static void main( String args[] ) { String sentence ...

Select from multiple tables in DBIx::Class

I have the following DBIx::Class code : my $where = 'me.loginid = ? AND me.code = ?'; my @bind = ( $loginID, $code ); my $tip_signals = $bom_schema->resultset('Table1')->search_literal( $where, @bind, { join => 'table2', group_by => [ 'me.id' ], '+select' => [ {'count' => '*'}, 'table2.id' ], '+a...

How do I get the speed of an Apple Airport from Perl?

I would like to be able to get the speed of the wireless interface under Mac OS X. I have a perl script that gets the other information for the wireless card but I still need to get the connection speed. For the moment I have statically set the airport speed with: $airport_rate = "54"; (see code below). What command could I use to get...

Is there a way to retrieve process stats using Perl or Python?

Is there a way to generically retrieve process stats using Perl or Python? We could keep it Linux specific. There are a few problems: I won't know the PID ahead of time, but I can run the process in question from the script itself. For example, I'd have no problem doing: ./myscript.pl some/process/I/want/to/get/stats/for Basically, I'...

How can I use vim to edit text from Perl while the script is still running?

I have a Perl script that outputs text. I want to import this text into vim, edit it, save it and then exit. On exit, I want the original Perl script to process the edited file. E.G. how crontab -e works when you add a new job. Thanks :) ...

How do I tell CPAN.pm to install all modules in a specific directory?

I have set makepl_arg [INSTALLDIRS=site PREFIX=~/perl] mbuildpl_arg [--install_base ~/perl] in the CPAN.pm configuration. I had hoped that this would cause modules to get installed in the same place, but I still have to set multiple paths in PERL5LIB: export PERL5LIB=~/perl/share/perl/5.10.0:~/perl/lib/perl5/:~/perl/l...