graq has asked for the wisdom of the Perl Monks concerning the following question:

I am getting an error, and am finding it difficult to ascertain the exact reason why the error is being logged.
(The whole script is CARP'd)

error:
Sort subroutine didn't return single value.
script.pl died with a software error

Code snippet:

my $messages = get_arrayref_of_objects; eval { $messages = [ sort { $a=>rank <=> $b->rank } @$messages ]; }; # + EVAL1 $LOG_OB->warning( "Sort failed: $@" ); foreach my $message (@$messages) { eval { $message->do_some_method; }; #EVAL2 # <1> if ($@) { $LOG_OB->fatal( "YOIKES: $@" ); } }
Now I know that the sort (at EVAL1)is failing, because the 'rank' method does not exist on the 'message' object.

But why is the sort failure logging this error?
Is $@ still defined at <1> even though the previous eval has no problems (EVAL2 never fails)?
Or is it something completely different and I am barking up the wrong tree?

--
Graq

Replies are listed 'Best First'.
Re: Perl behaviour - is it '$@' or 'sort' causing me grief?
by runrig (Abbot) on Sep 19, 2001 at 20:13 UTC
    # Look closely: sort { $a=>rank <=> $b->rank } @$messages # Your sort sub is returning (I think): ($a, (rank <=> $b->rank))
Re: Perl behaviour - is it '$@' or 'sort' causing me grief?
by boo_radley (Parson) on Sep 19, 2001 at 22:29 UTC
    s/=>/->/; is a good start, I bet :-)
      Kicks himself That's a typo, I was in a real rush when I posted that, had way too many things on my plate at once.
      Pasting the code snippet in would have been no good, so I improvised off the top of my head. Stupid, stupid.

      I'll just go off and test it myself, stop being such a lazy bugger.

      Oh, and thanks for the smart replies ;P

      --
      Graq