in reply to Error Handling Misconception

if i understand $@ correctly: it contains an error message for the "most recent" statement. in this case it's supposed to be the eval, but instead it's the assignment, which resets $@ to null. so the loop should be
while (eval { my $value = $object->next_val() }) { # do cool stuff } print "Error: $@\n" if($@);

Replies are listed 'Best First'.
Re: Re: Error Handling Misconception
by John M. Dlugosz (Monsignor) on Sep 04, 2003 at 14:54 UTC
    According to perlvar,

    $EVAL_ERROR
    $@
    The Perl syntax error message from the last eval() operator. If $@ is the null string, the last eval() parsed and executed correctly (although the operations you invoked may have failed in the normal fashion). (Mnemonic: Where was the syntax error ``at''?)

    Warning messages are not collected in this variable. You can, however, set up a routine to process warnings by setting $SIG{__WARN__} as described below.

    Also see Error Indicators.