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