ooooops.
ok I worked it out I changed the following code in the loop.

foreach my $mod ( @modules )
{
        $string="require $mod";
        eval {eval ($string);};
        if ($@)
        {
                my $obj = CPAN::Shell->expand('Module',$mod);
                $obj->install
        }
}


Hmmmmmm Perhaps a little bit more patience is needed today:-)

Marty

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> Martin Moss
> Sent: Wednesday 21 March 2001 16:20
> To: [EMAIL PROTECTED]
> Subject: [Perl-unix-users] Checking if a module is installed
> 
> 
> All,
> I've devised the following script to check if a CPAN module is 
> installed on
> a machine, and install it if it isn't.
> The only problem is, the eval always fails and says it can't find the
> module, and thus always installs it.
> Also if I use "use" instead of "Require" it gives me compilation errors.
> 
> Having a brain dead day, anybody know where I'm going wrong?
> 
> regards
> 
> Marty
> 
> 
> 
> 
> #!/usr/bin/perl
> 
> use CPAN;
> use strict;
> 
> my @modules = (
>              "MIME::Base64",
>              "MD5",
>              "URI",
>              "LWP",
>              "Data::Dumper",
>              "IO::ScalarArray",
>              "Time::HiRes",
>              "Time::CTime",
>              "Date::Format",
>              "File::Spec",
>              "Getopt::Long",
>              "AppConfig",
>              "Net::NNTP",
>              "Net::FTP",
>              "Net::SNMP",
>              "NetServer::Generic",
>              "Template",
>              "DBI",
>              "DBD::mysql",
>              "Mail::Internet",
>              "MIME::Parser",
>              "XML::Parser",
>              "XML::Simple",
>                );
> 
> # Install modules
> #
> foreach my $mod ( @modules )
> {
>         eval {require $mod;};
>         if ($@)
>         {
>                 my $obj = CPAN::Shell->expand('Module',$mod);
>                 $obj->install
>         }
> }
> 
> print "\n\nDone.\n";
> 
> _______________________________________________
> Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users
_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users

Reply via email to