R
Randal L. Schwartz
Rainer> If sort would return pi in scalar context, that would also be useful
Rainer> in some specific situations (as would any other value). But there is
Rainer> no more relation between the function of sort (return a specific
Rainer> permutation of its arguments) and 3.1415... than there is between
Rainer> permuting arguments and counting arguments.
I even addressed this point beginning in one of the early editions of
"Learning Perl", adding that being undefined, there was nothing
preventing sort in a scalar context from invoking "nethack". I do
recall a patch some number of years later (in jest) on P5P to do exactly
that.
The only serious proposals for scalar sort that I've seen are (a) a
boolean to say "yes, this list is already sorted", or perhaps (b) a
value between 0 and 1 as to "how sorted" the list already was, based on
a single pass of the sort comparator against adjacent elements. Not
sure when I would have used either one though.
if (sort { $a <=> $b } @list) { # this is already numerically sorted
...
}
print "Just another Perl hacker,"; # the original
Rainer> in some specific situations (as would any other value). But there is
Rainer> no more relation between the function of sort (return a specific
Rainer> permutation of its arguments) and 3.1415... than there is between
Rainer> permuting arguments and counting arguments.
I even addressed this point beginning in one of the early editions of
"Learning Perl", adding that being undefined, there was nothing
preventing sort in a scalar context from invoking "nethack". I do
recall a patch some number of years later (in jest) on P5P to do exactly
that.
The only serious proposals for scalar sort that I've seen are (a) a
boolean to say "yes, this list is already sorted", or perhaps (b) a
value between 0 and 1 as to "how sorted" the list already was, based on
a single pass of the sort comparator against adjacent elements. Not
sure when I would have used either one though.
if (sort { $a <=> $b } @list) { # this is already numerically sorted
...
}
print "Just another Perl hacker,"; # the original