2009/12/15 Xiao Lan (小兰) <practicalp...@gmail.com>: > On Tue, Dec 15, 2009 at 6:34 PM, Shlomi Fish <shlo...@iglu.org.il> wrote: >> You can use block eval {} instead of string eval "": > I did have tried that, but this will get a runtime error. > > # perl -e ' > eval { $x = 12/0 }; > if ($@) { print "0 div error" }' > > Illegal division by zero at -e line 2.
[OT: Are you running this as root? You should avoid being root whenever you can.] That's odd. It works on my machine: $ perl -le ' eval { $x = 12/0 }; if ($@) { print "0 div error" }' 0 div error $ perl -v This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi I can only guess that perl5.8.8 is not catching exceptions in constants caused by evaluating compile time constants. String eval delays evaluation to runtime which would stop this bug manifesting; but this feature is exactly the reason why string eval is /bad/. Does this work for you? $ perl -le 'eval { die "died"; }; if ($@) { print "Caught exception"; }' I would expect this to print "Caught exception" and not "died", which indeed is what happens on my machine. Phil -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/