From: Michael G. Schwern Date: Sat, 23 Jul 2005 19:59:29 +0000 (-0700) Subject: Re: [perl #36616] bug or feature? foreach (sort @array) {y/a-z/A-Z/;} # @array modified! X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db5021a3fd19311dd30fae8f0434571b4c0b93d1;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #36616] bug or feature? foreach (sort @array) {y/a-z/A-Z/;} # @array modified! Message-ID: <20050724025929.GA6574@windhund.schwern.org> p4raw-id: //depot/perl@25258 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 0bbd489..63fba1d 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4930,6 +4930,12 @@ loop control operators described in L or with C. When C is in effect, C sorts LIST according to the current collation locale. See L. +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, C or C) +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 go quadratic. (A I sort preserves the input order of elements that compare equal. Although