On Thu, Jul 18, 2002 at 11:39:15PM -0400, belg4mit wrote: > Heh I just came across this today. It's an interesting optimization, > but does it occur that often? It also precludes the possiblity of action at a > distance / more complicated sort blocks/subroutines doing more than just > sorting...
If sort is used in void or scalar context it's a no-op, that's about the extent of the optimization. Very simplistic, nothing like Haskell. In fact, perl will warn you about this, but the fellow below didn't have warnings on. $ perl -wle 'sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1)' Useless use of sort in void context at -e line 1. $ perl5.8.0 -wle '$a = sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1)' Useless use of sort in scalar context at -e line 1. The behavior of sort in scalar context is officially undefined because nobody could agree on what it should do. This causes subtle bugs. $ perl -wle 'sub foo { return sort qw(3 2 1) } print scalar foo' Use of uninitialized value in print at -e line 1. -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One Let me check my notes. http://www.sluggy.com