Dec 08

From time to time I need to create a utility that will work on one of my customer’s messaging systems to monitor something about it. Since Ruby isn’t on a lot of these systems (yet) I usually end up having to use Perl to create these utilities. Once nice thing about Perl is that there are lots and lots of packages out there that already do all sorts of functions. So after I have found the package that I need, I go out and see if its already on the messaging system. Since a standard Perl installation has any number of places where the package could be, I wrote this quick little Perl script to go parse through the @INC directories and print out all the package names it can find. The output can then be grep’d for the package in question quite easily.

Here’s the code:

#  --  Print out all the packages in the @INC paths.
#     Useful if you want to see if a particular package is on your system or not.
#  John D. Allen, June 2009

use File::Find;

$cdir = "";
find(\&wanted, @INC);

sub wanted {
   if (/\.pm$/) {
      if ($cdir ne $File::Find::dir) {
         $cdir = $File::Find::dir;
         print "\n$cdir:\n";

      open(PM, $File::Find::name);
      while(<PM>) {
         if (/^\s*package\s*(.*);/) {
            print "$1\n";
      close (PM);


You may need to change the first line, as my Perl home directory is not in a default location.

SociBook Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: