in reply to Re: runtime "use" statements via string eval
in thread runtime "use" statements via string eval
In the first case a required module isn't installed and the script dies with a link to the dist on CPAN:
Second case just causes some form buttons and text to not be printed later:eval("use XML::Simple 'XMLin'"); # required xml parser if($@){&install_xml_simple(); exit} sub install_xml_simple { print header; print qq~Install <a href='http://search.cpan.org/search?dist=XML-Simple'>XML::Simple</a +>~; }
And another switch if the script doesn't find a self-created data file:my$trade = 0; eval("use Compress::Zlib"); unless($@){$trade = 1} # if installed enable export/import
use vars qw($xpdat1 $dat1); my($xpdata,$data,$md,$nodat) = 0; # vars for next block my$df = 'some.data'; if(-e $df){ if(eval "require '$df'"){ $md = (stat($df))[9]; $xpdata = $xpdat1; $data = $dat1; } } else{ $nodat = 1 }
|
|---|