Perl Advent Calendar 2007-12-05

All I want for Christmas is Perl 5.10

by Josh McAdams

Word on the street is that there is a hot new item out this year that might be ready in time for Christmas. This new Perl 5.10 is the gift to get. Of course, Santa is a little sneaky so you might get a new Perl and not even realize it. To check your system and see if you've been given the gift of Perl we'll use File::Which.

File::Which is a portable implementation of the Unix which utility in that it searches the appropriate search path for your system and shows you the location of the executable that will be run if you just type a program name in on the command line. If called in a scalar context, then only the first executable is returned. In a list context, every instance of that program that can be found in your program search path is returned; a synonym for this latter behavior is the intuitively named where.

Also note the potential for alternative uses of this module beyond the usual location of an executable in $ENV{PATH}, namely finding things in other PATH-like variables such as $ENV{MANPATH}, $ENV{PERL5LIB} or $ENV{CLASSPATH}) by temporarily clobbering the global with local $ENV{PATH} = ... — The Mgt

   1 use File::Which;
   3 for my $perl ( where('perl') ) {
   4     my $output = `$perl -v`;
   5     if ( $output =~ /v(\d+\.\d+\.\d+)/ ) {
   6         my $version = $1;
   7         if ( $version =~ /5\.10/ ) {
   8             print "Santa brought us Perl $version and left it at $perl\n";
   9         }
  10         else {
  11             print "Crummy old Perl $version is still at $perl\n";
  12         }
  13     }
  14 }