Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Dangerous Names

by samtregar (Abbot)
on Dec 17, 2008 at 21:58 UTC ( #731068=note: print w/replies, xml ) Need Help??

in reply to Re: Dangerous Names
in thread Dangerous Names

Incorrect! Proof:

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

Note that you have to work a little. Just a straight { $a <=> $b } gets optimized into something that doesn't do the NaN conversion.


Replies are listed 'Best First'.
Re^3: Dangerous Names
by ikegami (Pope) on Dec 17, 2008 at 22:04 UTC
    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
      Ok - but do you find it unusual that sort { $a <=> $b } doesn't die, but sort { $a->[0] <=> $b->[0] } does?


        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://731068]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-07-06 03:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found