in reply to Use a module only if it is available
I can't take credit for this idea, but I've seen it done in places, and use it myself. I think I saw it in Term::ReadLine:
unless ( eval "use Packagename; 1" ) { print "Packagename not available!!\n"; }
The idea is that if things go wrong with the use statement, then the 1 never gets evaluated and the eval will pass back a false value, but if things go ok, then eval will pass back a true value ( 1, the last statement evaluated).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Use a module only if it is available
by rob_au (Abbot) on Jan 19, 2003 at 12:25 UTC |