Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Sorting Puzzle (just sort)

by imp (Priest)
on Feb 20, 2007 at 22:26 UTC ( #601226=note: print w/ replies, xml ) Need Help??


in reply to Re: Sorting Puzzle (just sort)
in thread Sorting Puzzle

$a <=> $b already forces $a and $b to be interpretted as numbers, always.
It doesn't appear to with perl 5.8.2:
use strict; use warnings; my $d1 = '2007030110300020070301133000'; my $d2 = '2007030110300020070301143000'; printf "plain = %d\n", ($d1 <=> $d2); { use bigint; printf "bigint = %d\n", ($d1 <=> $d2); } { use bigint; printf "bigint-0 = %d\n", (($d1 -0)<=> ($d2-0)); }
Output:
plain = 0 bigint = 0 bigint-0 = -1


Comment on Re^2: Sorting Puzzle (just sort)
Select or Download Code
Re^3: Sorting Puzzle (just sort)
by tye (Cardinal) on Feb 20, 2007 at 22:31 UTC

    That doesn't show $d1 and $d2 being compared as not numbers and so doesn't contradict my point. I guess the other points are about getting bigint to magically turn numeric expressions into objects. I'm not a fan of such subtle magic and so didn't recommend the use of bigint.pm and see no real value for it here anyway. But thanks for indirectly clarifying those points.

    - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-04 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls