Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Optional modules?

by castaway (Parson)
on Feb 27, 2003 at 12:54 UTC ( [id://239080]=note: print w/replies, xml ) Need Help??


in reply to Optional modules?

The accepted solution seems to be to use eval with require (You can't do a 'use' inside an 'eval').
my $loaded; { # ignore warnings if subs are being redefined local $^W = 0; $loaded = eval "require MQSeries"; } if(!defined($loaded)) { print "Can't load MQSeries: $@\n"; }
Note: you'll need an 'import' in there if you also want to import exported methods etc.

update: Apparently 'use' does work in 'eval', I can't for the life of me remember why I thought you can't, must have been some reason that I use require.. hohum..

C.

Replies are listed 'Best First'.
Re: Re: Optional modules?
by tachyon (Chancellor) on Feb 27, 2003 at 13:02 UTC

    You can't do a 'use' inside and 'eval'

    eval "use CGI"; $q = new CGI; print $q->header; __DATA__ Content-Type: text/html; charset=ISO-8859-1
    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found