From 0319020171ad67607dd7a06e238d6c91ff7d4639 Mon Sep 17 00:00:00 2001 From: "John P. Linderman" Date: Thu, 10 Jul 2003 06:45:06 -0400 Subject: [PATCH] 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 --- pod/perlfunc.pod | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 1.8.3.1