Perl Info


Library Path

From perlrun, supply paths to location of .pm package files for inclusion with use statement in the PERL5LIB environment variable.

Additional repositories for Win32

Useful CPAN modules



    use Switch;
    switch ($val) {
    case 1        { print "number 1" }
    case "a"    { print "string a" }
    case [1..10,42]    { print "number in list" }
    case (@array)    { print "number in list" }
    case /\w+/    { print "pattern" }
    case qr/\w+/    { print "pattern" }
    case (%hash)    { print "entry in hash" }
    case (\%hash)    { print "entry in hash" }
    case (\&sub)    { print "arg to subroutine" }
    else        { print "previous case not true" }


From perlsub at

  • The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities—but you may always use pass-by-reference instead to avoid this.


See perldebtut and perldebug at Some information from there:

  • Launch using perl -d <filename>
  • Commands:
    • Quit: q
    • Summary Help: h
    • Complete Help: h h
    • View around line: v
    • Single step: s
    • Continue until position: c
    • Evaluate expr: x expr
    • Print expr using script packages (useful for pdls): p expr
    • Reset view to line about to execute: .
    • Print key/value pairs: x \%hash
  • Set a breakpoint in code by adding the line: $DB::single=1;

Define some useful Constants

$PI = 2*asin(1); # Mmmm, PI
$DTOR=180/$PI; # Degrees to radians conversion multiplier
$RADEG=$PI/180; # Radians to degrees conversion multiplier

# Handy script to scrub out the m4a files in iTunes where an mp3 file exists
use File::Find;
sub get_m4a {
 # Match on files with .m4a extension (that don't start with a .)
 if (/^([^\.].*)\.m4a$/) { # $1 contains filename sans extension
 # See if the mp3 file for it exists and if so, delete the m4a version
 if(stat("$1.mp3")) {
  print(STDOUT "Purging: $1.m4a\n");
  # Do the delete
  # And while we're here, delete the ._ m4a file as well
find(\&get_m4a, ".");
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License