Re: [perl #36616] bug or feature? foreach (sort @array) {y/a-z/A-Z/;} # @array modified!
authorMichael G. Schwern <schwern@pobox.com>
Sat, 23 Jul 2005 19:59:29 +0000 (12:59 -0700)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 1 Aug 2005 14:45:22 +0000 (14:45 +0000)
Message-ID: <20050724025929.GA6574@windhund.schwern.org>

p4raw-id: //depot/perl@25258

pod/perlfunc.pod

index 0bbd489..63fba1d 100644 (file)
@@ -4930,6 +4930,12 @@ loop control operators described in L<perlsyn> or with C<goto>.
 When C<use locale> is in effect, C<sort LIST> sorts LIST according to the
 current collation locale.  See L<perllocale>.
 
+sort() returns aliases into the original list, much as a for loop's index
+variable aliases the list elements.  That is, modifying an element of a
+list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>)
+actually modifies the element in the original list.  This is usually
+something to be avoided when writing clear code.
+
 Perl 5.6 and earlier used a quicksort algorithm to implement sort.
 That algorithm was not stable, and I<could> go quadratic.  (A I<stable> sort
 preserves the input order of elements that compare equal.  Although