Archive for the ‘Perl’ Category

Profiling Perl

Tuesday, June 17th, 2008

# perl -d:DProf test.pl
hello

# ls
test.pl  tmon.out

# dprofpp tmon.out

Total Elapsed Time = 0.009982 Seconds
User+System Time = 0.009982 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
100.   0.010  0.010      1   0.0100 0.0100  warnings::BEGIN
0.00       - -0.000      1        -      -  strict::import
0.00       - -0.000      1        -      -  strict::bits
0.00       - -0.000      1        -      -  warnings::import
0.00       -  0.010      2        - 0.0050  main::BEGIN

libMagick.so.10: cannot open shared object file

Tuesday, June 3rd, 2008

Can’t load ‘…/auto/Image/Magick/Magick.so’ for module Image::Magick: libMagick.so.10: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230.

  1. Add /usr/local/lib to /etc/ld.so.conf
  2. Run ldconfig as root.

Change URLLIST in CPAN due to lagging

Wednesday, May 7th, 2008

To remove the first entry in the urllist, do this:

o conf urllist shift

This will make CPAN use the next FTP site in the queue.

How to Fork in Perl

Wednesday, March 26th, 2008

Kick off multiple processes simulataneously in Perl.

my $num = 10;

my @children;

for (my $i = 0; $i < $num; $i++) {
my $pid = fork();
if ($pid) { # parent
push @children, $pid;
} elsif ($pid == 0) { # child
print "child $i\n";
sleep 5;
exit;
} else {
print STDERR "couldn't fork\n";
}
}

foreach my $child (@children) {
waitpid($child, 0);
}