From: John P. Linderman Date: Thu, 10 Jul 2003 10:45:06 +0000 (-0400) Subject: Re: Sort sub and NaNs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0319020171ad67607dd7a06e238d6c91ff7d4639;p=p5sagit%2Fp5-mst-13.2.git Re: Sort sub and NaNs From: "John P. Linderman" Message-Id: <200307101445.KAA79110@raptor.research.att.com> Warn against a potential edge case with sort, <=> and NaNs. p4raw-id: //depot/perl@20156 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 3686736..612b9cd 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4758,6 +4758,15 @@ inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and sometimes saying the opposite, for example) the results are not well-defined. +Because C<< <=> >> returns C when either operand is C +(not-a-number), and because C will trigger a fatal error unless the +result of a comparison is defined, when sorting with a comparison function +like C<< $a <=> $b >>, be careful about lists that might contain a C. +The following example takes advantage of the fact that C to +eliminate any Cs from the input. + + @result = sort { $a <=> $b } grep { $_ == $_ } @input; + =item splice ARRAY,OFFSET,LENGTH,LIST =item splice ARRAY,OFFSET,LENGTH