perl

Is there a way to caching mechanism for Class::DBI?

I have a set of rather complex ORM modules that inherit from Class::DBI. Since the data changes quite infrequently, I am considering using a Caching/Memoization layer on top of this to speed things up. I found a module: Class::DBI::Cacheable but no rating or any reviews on RT. I would appreciate hearing from people who have used this or ...

Difference in regex behavior between Perl and Python?

I have a couple email addresses, '[email protected]' and '[email protected]'. In perl, I could take the To: line of a raw email and find either of the above addresses with /\w+@(tickets\.)?company\.com/i In python, I simply wrote the above regex as '\w+@(tickets\.)?company\.com' expecting the same result. However, support...

Shell: insert a blank/new line two lines above pattern

I have a text file and it requires some formatting. I know that if you want to add a blank line above every line that matches your regexp, you can use: sed '/regexp/{x;p;x;}' But I'd like to add a blank line, not one line above, but two lines above the line which matches my regexp. The pattern I'll be matching is a postal code, in th...

Perl script to parse output of cvs log command

Does anyone have a perl script or package that parses the output of a cvs log command and turns it into perl structures for further processing? ...

How to flush output in backticks In Perl?

If I have this perl app: print `someshellscript.sh`; that prints bunch of stuff and takes a long time to complete, how can I print that output in the middle of execution of the shell script? Looks like Perl will only print the someshellscript.sh result when it completes, is there a way to make output flush in the middle of execution...

What should I use instead of printf in Perl?

I need to use some string replacement in Perl to ease translations, i.e. replace many print "Outputting " . $n . " numbers"; by something like printf ("Outputting %d numbers", $n); However, I'd like to replace printf with something easier to parse for humans, like this: printX ("Outputting {num} numbers", { num => $n }); or gene...

Easiest way to open a text file and read it into an array with Perl

Adding a standard Perl file open function to each script I have is a bit annoying: sub openfile{ (my $filename) = @_; open FILE,"$filename" or die $!; my @lines = <FILE>; return @lines; } and I can create a Perl module to do this, but this is so simple I'm sure there should be one out there already. I'm trying to find...

Is the UID provided by MS Exchange POP3 UIDL command truly unique?

I'm using Net::POP3 in Perl to iterate through a mailbox on an MS Exchange server. I run the UIDL command on each message number and compare the ID returned to previously-seen IDs to see if I've dealt with this message in the past. However, I'm also finding that within an individual POP3 mailbox, the same UID seems to come up multiple ti...

Sort by value hash of hash of hashes Perl

I have a hash structure similar to the following: KeyA => { Key1 => { Key4 => 4 Key5 => 9 Key6 => 10 } Key2 => { Key7 => 5 Key8 => 9 } } KeyB => { Key3 => { ...

Does 'use lib' work for UNC paths?

My hosted scripts have been moved and no longer work. The specified CGI application misbehaved by not returning a complete set of HTTP headers. I notice that someone at my host company has modified my scripts so that where I used to have use lib 'd:/myorig/LIB'; I now have use lib '//newhost/LIB'; Should this work? I tri...

Can I substitute multiple items in a single regular expression in VIM or Perl?

Let's say I have string "The quick brown fox jumps over the lazy dog" can I change this to "The slow brown fox jumps over the energetic dog" with one regular expression? Currently, I use two sets of regular expressions for this situation. (In this case, I use s/quick/slow/ followed by s/lazy/energetic/.) thanks. ...

How can I run a Perl script as a system daemon in linux?

What's a simple way to get a Perl script to run as a daemon in linux? Currently, this is on CentOS. I'd want it to start up with the system and shutdown with the system, so some /etc/rc.d/init.d integration would also be nice, but I could always add a custom line to /etc/rc.d/rc.local. ...

Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?

Given an alternation like /(foo|foobar|foobaz)/ does Perl 5.8 or 5.10 make any promises about which of the three will be used first, and if it does where in the documentation does it make that promise? See the related question Does Perl 6 make any promises about the order alternations will be used? ...

Are there good resources for porting mod_perl to Catalyst & is it worth it?

We have a big e-learning mod_perl web app, which use AxKit, XML, XLST and javascript primarily running on a unix server. What I've came to notice is that the codes are rather messy, and there has been a few generations of developers coming in and out. Due to the current structure, the task of trying to make a simple hello world webpage i...

How can I make Perl's a2p support gawk?

I have some awk scripts that use gawk from cygwin. Now I need to pass these scripts to colleagues that don't have cygwin installed, but do have Perl. I was hoping I can just use a2p that is included in cygwin, but it fails with errors like the following: Undefined subroutine &main::gensub called at ./t.pl line 18, <> line 1. I am hopi...

How can I check if a Windows device driver is loaded using Perl?

I was wondering how I could check if a device driver is loaded using Perl? The operating system is Windows Server 2003, and I'm interested in seeing if the driver for a particular video card is loaded correctly or not. ...

Where is the good documentation for Catalyst?

Hello! I have a problem with understanding the Catalyst MVC framework. I have read a Catalyst book and documentation from CPAN for Catalyst, but I am still a noob and don't understand how to work with this. I am looking for good examples and documentation for Catalyst that describes how to work with classes, databases, and templates. ...

How do I get full Win32 path from 8.3 DOS path with Perl?

Hi all! My question basically says it all. I am getting this: C:\DOCUME~1\frew\MYDOCU~1\Code\AIRCRA~1\lib\ACD\VALIDA~1.PM and I want this: C:\Documents and Settings\frew\My Documents\Code\aircraft_ducting\lib\ACD\Validators.pm I looked at File::Spec::Win32 but that didn't seem to have anything that would do the trick. Ideas? T...

How can I convert four characters into a 32-bit IEEE-754 float in Perl?

I have a project where a function receives four 8-bit characters and needs to convert the resulting 32-bit IEEE-754 float to a regular Perl number. Seems like there should be a faster way than the working code below, but I have not been able to figure out a simpler pack function that works. does not work - seems like it is close $floa...

Setting default value with Params::Validate if an undefined value is passed in

Hi Perl followers. I am having trouble getting Params::Validate to work how I want it to. #!/usr/local/bin/perl -w use strict; use Params::Validate qw/:all/; use Data::Dumper; sub foo { my %args = validate(@_, { bar => { default => 99, # TODO - Somehow use a callback to return a default if undefine...