From db5021a3fd19311dd30fae8f0434571b4c0b93d1 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 23 Jul 2005 12:59:29 -0700 Subject: [PATCH] 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 --- pod/perlfunc.pod | 6 ++++++ 1 file changed, 6 insertions(+) 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 -- 2.7.4