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

eval is also Perl's mechanism for exception-trapping.

Replies are listed 'Best First'.
Re^4: what difference between eval and do ?
by ikegami (Patriarch) on Apr 19, 2018 at 20:14 UTC

    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.

        Nope, it only illustrates an inconsequential difference I didn't even know about before the OP posted it.