demerphq has asked for the wisdom of the Perl Monks concerning the following question:
Now you would expect that these would all output the same thing. But they dont!sub capture {\@_}; # the eval here returns 1 to make for a cheap check for success. # we could check $@ but why bother? sub readonly{ my $v=$_[0]; eval{$_[0]=$v;1} ? 0 : 1 } $\="\n"; print "No eval :",readonly(capture(5)->[0]); eval ' print "In str eval :",readonly(capture(5)->[0]); '; eval { print "In block eval :",readonly(capture(5)->[0]); }; print "Block Eval ret :",readonly(eval{capture(5)}->[0]); print "Str Eval ret :",readonly(eval'capture(5)'->[0]);
Can anybody explain this behaviour? Is it consistent across perl versions? (tested 5.6.1 AS631)No eval :1 In str eval :1 In block eval :1 Block Eval ret :1 Str Eval ret :0
Why should the return from a string eval be any different from the return from a block eval? (podmaster suggests that this is documented somewhere.. But so far cant find it. Can anybody else?)
Do you agree that this is a bug in perl that should be reported?
Thanks for you help in advance,
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.
|
|---|