Joe Gottman wrote in perl.perl6.language : > This is unrelated to the problem you mentioned, but there is another > annoying problem with sort as it is currently defined. If you have an > @array and you want to replace it with the sorted version, you have to type > @array = sort @array; > > Besides being long-winded, this causes Perl to make an unnecessary copy of > the array. It would be nice calling if sort (or reverse, or other similar > functions) in void context resulted in in-place modification of the array > that was input.
I'd rather not change the behaviour of sort (or other built-ins that may or may not operate in place) depending on the calling context. What to do, for example, when C<sort> is the last statement of a sub? Besides this, a construction like @x = sort @x could be detected by a suitable optimizer and turned to (internally) an in-place sort. (It appears that Dave Mitchell is working on such an optimization for perl 5.)