in reply to Re: Question about eval
in thread Question about eval

why does perl allow me to hand a print statement a junk token if I do not use strict ?

It's a filehandle, not a junk token. There's no way at compile time to know whether the filehandle has been opened or not, so STDOUT, FH, petrol, $fh are all the same and all perfectly valid.

I am still not 100% on eval.

require either returns true, or throws an exception. eval catches exceptions. You can check if an exception has been caught or not by checking $@.

eval returns undef if an exception has been caught, so you can also do something like

if (eval { require "module/that/does/not/exist"; 1 } ) { print "loaded module ok\n"; } else { print "could not load module: $@\n"; }

or since require always returns true,

if (eval { require "module/that/does/not/exist" } ) { print "loaded module ok\n"; } else { print "could not load module: $@\n"; }