Find & Checking Modules Used by Perl Programs

Discussion in 'Perl' started by pradeep, Aug 29, 2009.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Say you have a couple of Perl programs and you would like to know what modules are used by the programs, and may be you would also like to know what are the module versions and if they exists or not.

    Here is a combination of common commands to list and print module version, and print a message if the module does not exists.

    Code:
    egrep '^[\s\t]*use[ ]+[a-zA-Z:]' *.pl|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);'
    This will list the modules used by the .pl programs in the current directory. The next example will do a recursive search.

    Code:
    egrep -R '^[\s\t]*use[ ]+[a-zA-Z:]' *.pl|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);'
    Example output:
    Code:
    [root@pradeep:/var/www/cgi-bin] egrep -R '^[\s\t]*use[ ]+[a-zA-Z:]' *|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);'
    CGI => 3.38
    CGI::Carp => 1.30_01
    DBI => 1.607
    Data::Dumper => 2.121_08
    DateTime => 0.4304
    Digest::MD5 => 2.36
    missing Email::Valid
    LWP::Simple => 5.810
    LWP::UserAgent => 5.814
    MIME::Base64 => 3.07
    MIME::Lite => 3.022
    Net::SMTP_auth => 0.08
    missing PAB3::Crypt::XOR
    POSIX => 1.09
    Parallel::ForkManager => 0.7.5
    missing Slurp
    
    Enjoy! Update if you have any ideas.
     
  2. ungalnanban

    ungalnanban New Member

    Joined:
    Feb 19, 2010
    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    Chennai
    ExtUtils::Installed

    this module is used to show all installed distributions,

    sample code:
    Code:
                            use ExtUtils::Installed;
                            use Data::Dumper;
                            my ($inst) = ExtUtils::Installed->new();
                            my (@modules) = $inst->modules();
                            print  Dumper \@modules;
    
    To list of all of the Perl module filenames use the File::Find module:

    - Example:
    -------

    Code:
         use Data::Dumper;
         use File::Find;
         my @files;
         find(     sub {   
    
    push @files, $File::Find::name if -f $File::Find::name && /\.pm$/
                   },  
         @INC      );
    
        print Dumper \@files;
    
    
    The above code will display the all *.pm files in your system.
     
  3. Abinila

    Abinila New Member

    Joined:
    Feb 20, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    I'm trying to figure out how to automatically list all the modules used by
    a particular program.

    Try this,
    foreach (sort keys %INC) {print "$_\n"}

    This will give default modules used by a particular program. If you include any module other than default things that also will include in your INC hash.
     
  4. thillai_selvan

    thillai_selvan New Member

    Joined:
    Feb 20, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    *{$glob}{PACKAGE} , *{$glob}{NAME}, these are all built in variables used to find the packages used in the current Perl program
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice