in reply to Re^2: Dangerous Names
in thread Dangerous Names

I didn't need to do any extra work. See my post below.
$ perl -v This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

Replies are listed 'Best First'.
Re^4: Dangerous Names
by samtregar (Abbot) on Dec 17, 2008 at 22:05 UTC
    Ok - but do you find it unusual that sort { $a <=> $b } doesn't die, but sort { $a->[0] <=> $b->[0] } does?

    -sam

      Ah, I see what you mean. You're wrong about it dying, though. It's only warning.

      I don't find it unusual since I've previously heard that { $a cmp $b }, { $a <=> $b }, { $b cmp $a } and { $b <=> $a } are handled specially to avoid having to call a Perl sub repeatedly.

      While I don't find it unusual, I do think the difference in behaviour is a bug.

        Oh, right, I have die on warnings running in this context I think.

        UPDATE: No, actually it does die. This is not a warning. Observe:

        $ perl -e '@names = (["Nan Tregar"], ["Sam Tregar"]); eval { @names + = sort { $a->[0] <=> $b->[0] } @names; }; print "ERROR WAS: $@"' ERROR WAS: Sort subroutine didn't return a numeric value at -e line + 1.

        -sam