Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: what difference between eval and do ?

by Anonymous Monk
on Apr 19, 2018 at 06:12 UTC ( [id://1213153]=note: print w/replies, xml ) Need Help??


in reply to Re: what difference between eval and do ?
in thread what difference between eval and do ?

Understood! eval is actually a anonymous sub call, but do is just a block! Thank you very much ikegami!
  • Comment on Re^2: what difference between eval and do ?

Replies are listed 'Best First'.
Re^3: what difference between eval and do ?
by sundialsvc4 (Abbot) on Apr 19, 2018 at 13:12 UTC
    eval is also Perl's mechanism for exception-trapping.

      I didn't take the title literally. The OP appears to asking why do BLOCK and eval BLOCK behave differently in the provided code. I did not set to list all the difference between eval BLOCK and do BLOCK, at least one of which hasn't been mentioned yet (do BLOCK's interaction with the while statement modifier).

        But your code already perfectly show the difference and the underlining reason between eval and do: they both return the value of the last statement in the block, eval is sub-call, so it copy the last value and return it; and do is a bit like a named block. that's it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found