Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: runtime "use" statements via string eval

by epoptai (Curate)
on Apr 04, 2001 at 07:44 UTC ( [id://69541]=note: print w/replies, xml ) Need Help??


in reply to Re: runtime "use" statements via string eval
in thread runtime "use" statements via string eval

I've come to similar solutions as footpad with slight variations.

In the first case a required module isn't installed and the script dies with a link to the dist on CPAN:

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 +>~; }
Second case just causes some form buttons and text to not be printed later:
my$trade = 0; eval("use Compress::Zlib"); unless($@){$trade = 1} # if installed enable export/import
And another switch if the script doesn't find a self-created data file:
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 }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-25 00:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found