Possible Duplicate:
How can I check if I have a Perl module before using it?
I’d like to eval a use statement similar to this: eval {use $foo;} but am having trouble with the correct syntax. I’ve tried various combinations of string interpolation, but the eval always succeeds even for a module that does not exist. Can someone give me hand with this one?
The idiom you are looking for is:
eval“always succeeds” in the sense that program execution will continue no matter what code is evaluated — that’s really the whole point of anevalstatement. If the evaluated string contained errors — run time or compile time — the return value of theevalcall isundefand the special variable$@will be set with an appropriate error message.The
usestatement, even when successful, does not return a value. That’s why this idiom includes the “; 1” at the end.