<?xml version="1.0" encoding="windows-1252"?>
<node id="68205" title="Answer: How do I do a natural sort on an array?" created="2001-03-29 20:15:28" updated="2005-08-11 06:39:20">
<type id="1888">
categorized answer</type>
<author id="11732">
QandAEditors</author>
<data>
<field name="doctext">
&lt;code&gt;
my @sorted= grep {s/(^|\D)0+(\d)/$1$2/g,1} sort
    grep {s/(\d+)/sprintf"%06.6d",$1/ge,1} @data;
&lt;/code&gt;
See [id://24841] some important style comments.
&lt;p&gt;
Features and limitations:
&lt;ul&gt;&lt;li&gt;Strips extra leading zeros from digit strings
&lt;/li&gt;&lt;li&gt;Doesn't handle floating point numbers at all well
&lt;/li&gt;&lt;li&gt;Sorts negative integers in reverse after positive integers
&lt;/li&gt;&lt;li&gt;Uses very little extra memory
&lt;/li&gt;&lt;li&gt;You must specify the maximum number of digits your
integers will have (6 in the above code)
&lt;/li&gt;&lt;/ul&gt;
</field>
<field name="parent_node">
68185</field>
</data>
</node>
