in reply to Question about eval
At what point of processing the script does an eval function get parsed ? Is it not compile time ? Or is it run time ?There are two types of eval which behave quite differently: eval STRING and eval BLOCK. If eval is passed a string parameter, it is parsed and compiled at runtime; if it is passed an unquoted block of code, it is parsed and compiled at compile-time.
Also, why doesrequire dies if it can't find the file it's looking for, rather than simply returning an error. require is a sort of assertion, and if it fails it's considered too severe to keep on running.not work ?if(require "module/that/does/not/exist") { print "loaded module ok\n"; }else{ print "could not load module $@\n"; }
if I doYes, you have to check $@ after every eval to see if anything in the eval failed.nothing happens ? Do I have to check $@ after eval ? Do i have to check if $@ is defined after every eval call ?eval { require "module/that/does/not/exist"; }
Also, why does this small print statement not generate error ?If you run perl without warnings and strict, undeclared variables simply spring into existence. In this case, petrol is created the first time you use it. It doesn't go anywhere, so output to it is simply discarded. If you add:print petrol "hello there !";
to the top of your Perl code, you'll get an error if you try to do this. I recommend starting off all of your scripts that way.use warnings; use strict;
|
|---|