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

Re: [perl #69384] numericness failure in sorting

From:
David Nicol
Date:
September 25, 2009 12:22
Subject:
Re: [perl #69384] numericness failure in sorting
Message ID:
934f64a20909251221t8c76791p2022b936b2b6b599@mail.gmail.com
On Fri, Sep 25, 2009 at 12:38 PM, John P. Linderman
<jpl@research.att.com> wrote:

> perldoc -f sort
>
> is pretty clear about wanting integer returns...
>
>    If SUBNAME is specified, it gives the name of a subroutine
>    that returns an integer less than, equal to, or greater
>    than 0, depending on how the elements of the list are to be
>    ordered.  (The "<=>" and "cmp" operators are extremely
>    useful in such routines.)
>
> (note *integer*, not "a string that looks like an integer")
> and the error message,


but this is Perl! Programmers are supposed to be allowed to be
careless about switching between numbers and strings.  How much of
"darkpan" is affected by this stricture? If Zefram were to deliver a
patch to, for instance, `perform a "looks-like-a-number" check and if
so, try again` in the spot where the exception in question is raised,
would that patch have a chance of achieving application?

Ideally, the "side effect numerification" would occur on the constant
string "1" in a COW manner, even though the value has changed hands a
couple of times, so that little smidge of CPU would only get used once
per constant instead of every time, or the numerification could be
made persistent by adding the :lvalue attribute to the comparison
routine.



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