On 05/14/2017 08:02 AM, Shawn H Corey wrote:
On Sun, 14 May 2017 02:08:11 +0100
lee <l...@yagibdah.de> wrote:
I haven't used 'eval' before, and this seems inherently dangerous.
eval EXPR;
eval;
These are dangerous.
eval BLOCK
This is not.
just to clarify and add to shawn's comments.
eval EXPR compiles and runs the perl code in the EXPR. it is very
dangerous but powerful. beginners pretty much should never need to use it.
eval BLOCK is actually a very different animal which unfortunately has
the same name. the block is compiled at the normal compile time (not
just when eval is called as with eval EXPR). but eval BLOCK is actually
meant to catch exceptions like die or fatal errors. it should be called
catch or similar and there are modules (typically named Try::*) which do
that and handle the errors more correctly.
so go and use eval BLOCK or a module that does it for you anytime you
need it.
do NOT use eval EXPR unless you can show there is no other way to solve
the problem. it is a solution of the last resort!
thanx,
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/