in reply to Question about eval
eval and require:
eval and use:if(eval { require "foo.pm"; 1; } ) { print "loaded module ok\n"; }else{ print "could not load module $@\n"; }
As for this line:if(eval " use foo; 1" ) { print "loaded module ok\n"; }else{ print "could not load module $@\n"; }
The reason why that does not generate an error is that the first argument to print can be a bareword, which is interpreted as a filehandle name. e.g.:print petrol "hello there !";
If you use strict and warnings (which you always should) then you will receive this error:print STDOUT "hello\n";
Unquoted string "petrol" may clash with future reserved word at p line + 3. Name "main::petrol" used only once: possible typo at p line 3. print() on unopened filehandle petrol at p line 3.
|
|---|