Xiao Lan (小兰) wrote:
eval "$x=12/0"; if ($@) { print "0 div error" }' 0 div error
Don't rely on testing $@, simply because it is a global variable that can get changed everywhere. Instead, test the return value of the eval itself. (Don't forget to let it return "1" for success, just like with modules.) Avoid string-eval whenever possible. perl -wle ' my $y = 0; if ( !eval { 42 / $y; 1 } ) { my $error = $@ || "unknown"; print $error; } ' Illegal division by zero at -e line 3. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/