hubb0r has asked for the wisdom of the Perl Monks concerning the following question:
and all has gone as planned. Horray! The problem is, what I want to do is the following:#!/usr/local/bin/perl -w use strict; print "You must be root to run this program\n" and exit 1 unless ($> = += 0); BEGIN { unless (eval { require Config::Auto }) { print "Need to install Config::Auto module. I'll do that for +you now:\n"; my $ret = system("perl -MCPAN -e 'install Config::Auto'"); print $ret; } }
but for some reason, the eval is returning false even though the modules do exist, and forcing my cpan installation to be attempted again.#!/usr/local/bin/perl -w use strict; print "You must be root to run this program\n" and exit 1 unless ($> = += 0); BEGIN { foreach my $module ( qw{Config::Auto Mail::Sendmail} ) { unless (eval { require $module }) { print "Need to install $module module. I'll do that for y +ou now:\n"; my $ret = system("perl -MCPAN -e 'install $module'"); print $ret; } } }
Which I somehow glossed over on my first reading of the perldoc. I'm glad I figured it out!eval {"require $module"}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Auto Install of Modules
by polettix (Vicar) on Aug 04, 2005 at 16:57 UTC | |
Re: Auto Install of Modules
by blazar (Canon) on Aug 04, 2005 at 17:31 UTC |