develooper Front page | perl.perl5.porters | Postings from September 2009

Re: [perl #69384] numericness failure in sorting

Thread Previous | Thread Next
From:
Eric Brine
Date:
September 25, 2009 11:56
Subject:
Re: [perl #69384] numericness failure in sorting
Message ID:
f86994700909251156ya28f73tf52782b099d03e21@mail.gmail.com
On Fri, Sep 25, 2009 at 8:21 AM, Zefram <perlbug-followup@perl.org> wrote:

> # New Ticket Created by  Zefram
> # Please include the string:  [perl #69384]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=69384 >
>


> Can also work around it by side-effect numerification:
>
> $ perl -lwe 'sub my_cmp { my $r = $_[0] < $_[1] ? "-1" : $_[0] == $_[1] ?
> "0" : "1"; { no warnings "void"; 0+$r; } return $r; } print sort {
> my_cmp($a, $b) } (1,5,4,7,2)'
> 12457
>

Wouldn't
    { no warnings "void"; 0+$r; } return $r;
be simpler as
    return 0+$r;


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About