Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm writing an installation script that needs to check if a few modules are installed. I'm not sure of the best way to go about this and would really appreciate a pointer on how to go about it.

many thanks

Replies are listed 'Best First'.
Re: script to check modules exist...
by Anonymous Monk on Apr 30, 2011 at 11:50 UTC
    That is called a Makefile.PL, see Module::Install - Standalone, extensible Perl module installer
Re: script to check modules exist...
by anonymized user 468275 (Curate) on May 02, 2011 at 14:31 UTC
    use Data::Dumper; my %g_modules; Traverse( $_ ) for ( @INC ); print Dumper \%g_modules; sub Traverse { my $dir = shift; opendir my $dh, $dir or die "$!: $dir\n"; for my $file ( grep !/^\./, readdir $dh ) { my $path = "$dir/$file"; if ( -d $path ) { Traverse ( $path ); } elsif ( $file =~ /\.pm$/ ) { $g_modules{ $file } = 1; } } closedir $dh; }

    One world, one people

      The results of your code are misleading because it tells me I only have one file named "Base.pm".
      'Base.pm' => 1,
      However, I have 22 installed files named "Base.pm"
      Chart/Base.pm DBD/Gofer/Policy/Base.pm DBD/Gofer/Transport/Base.pm DBI/Gofer/Serializer/Base.pm DBI/Gofer/Transport/Base.pm Date/Manip/Base.pm DateTime/Locale/Base.pm Exception/Class/Base.pm ExtUtils/CBuilder/Base.pm ExtUtils/Constant/Base.pm IO/Compress/Base.pm IO/Uncompress/Base.pm Log/Dispatch/Base.pm Module/Build/Base.pm Net/DNS/Resolver/Base.pm TAP/Base.pm TAP/Formatter/Base.pm URI/file/Base.pm XML/SAX/Base.pm YAML/Base.pm YAML/Dumper/Base.pm YAML/Loader/Base.pm
      See Find installed Perl modules matching a regular expression
        It is of course possible to store the full path as a hash key instead. But it is not easy to specify where the first part of the namespace begins from that, although a site-specific solution should be possible.

        One world, one people