<?xml version="1.0" encoding="windows-1252"?>
<node id="215550" title="Sorting Array in Place" created="2002-11-24 18:22:23" updated="2004-08-12 17:36:14">
<type id="115">
perlquestion</type>
<author id="177128">
dbp</author>
<data>
<field name="doctext">
Is there an idiomatic way to sort an array in place in Perl?  As far as I understand,

&lt;code&gt;
my @list = sort @list;
&lt;/code&gt;

incurs the overhead of creating a new array and copying the values into &lt;tt&gt;@list&lt;/tt&gt;; we get the same result as sorting a list in place but at greater cost.  It is conceivable that Perl is optimized to take advantage of code like this, but I don't know one way or another.  One could easily write a sub that performs some sorting algorithm (quicksort, mergesort, etc) on an array reference, but is there a way to coerce Perl's built-in functions to get the desired effect?</field>
</data>
</node>
