>>>>> "JWK" == John W Krahn <jwkr...@shaw.ca> writes:

  >> Also, how does 'eval' work and when is it useful? What is the difference if
  >> we put a block inside eval like: eval ( <block> };

  JWK> eval interprets a string as Perl code and compiles and runs it.  If
  JWK> you are using a block eval then the block must be valid Perl code and
  JWK> it is useful for capturing errors or warnings in the $@ variable.

eval won't catch warnings. but it does catch die calls. eval block is
perl's way to do exceptions handling.

an important note about eval STRING vs eval BLOCK. they are actually two
VERY different operators with the (unfortunately) same name. the string
version compiles and executes a perl code. it does also trap die
calls. the block version doesn't do anything but trap die calls. you
rarely need the string version (newbies tend to way overuse it). my rule
for string eval is you don't use it unless you learn when not to use
it. it isn't needed for data structures, symbolic references, etc.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to