perl.org wrote:
I want my code to call some subroutines in a custom module only if that module
exists on the system. I can think of at least three techniques to determine
if the module exists: scan @INC, use UNIVERSAL::can (not sure that would
work), or put the code in an eval block. What is the best solution? I think
an eval block sounds right, but I'm not sure. My guess would look something like:
eval
{
use module;
module::subroutine();
};
But the use statement of course throws a compiler error, so I think the
appropriate thing is to put this code into a string and eval that. But this
code is going to get replicated to a large number of files and I want the
shortest syntax possible, or if there is some better way...
use constant HAS_CONFIG_PM => (eval "use Config") || !$@;
print "has Config\n" if HAS_CONFIG_PM;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>