<?xml version="1.0" encoding="windows-1252"?>
<node id="24841" title="RE: RE: Re: Sorting on Section Numbers" created="2000-07-28 13:15:29" updated="2005-08-11 06:48:05">
<type id="11">
note</type>
<author id="22609">
tye</author>
<data>
<field name="doctext">
&lt;p&gt;You simplified it a lot by dropping &lt;code&gt;$maxdigs&lt;/code&gt;.  Put that back in and I doubt you'll have saved more than a keystroke or two.  :)  But thanks for the &lt;code&gt;substr&lt;/code&gt; method; I like that.&lt;/p&gt;
&lt;code&gt;
substr("0000$1",-4)
sprintf"%04.4d",$1
substr("0"x$maxdigs.$1,-$maxdigs)
sprintf"%0$maxdigs.$maxdigs"."d",$1
&lt;/code&gt;
&lt;p&gt;When I saw the name [chip], I wondered if it was you.  Welcome to Perl Monks!  I've run into your work many times and have been impressed.&lt;/p&gt;
&lt;p&gt;If you know you don't need extra leading zeros, then you can also get away with:&lt;/p&gt;
&lt;code&gt;
grep{s/(^|\D)0+(\d)/$1$2/g,1} sort
grep{s/(\d+)/sprintf"%06.6d",$1/ge,1} @sects;
&lt;/code&gt;
&lt;p&gt;Man, I shouldn't attempt this much thinking before breakfast.&lt;/p&gt;</field>
<field name="root_node">
24765</field>
<field name="parent_node">
24823</field>
</data>
</node>
