<?xml version="1.0" encoding="windows-1252"?>
<node id="521701" title="Re: sorting out directories" created="2006-01-07 03:22:42" updated="2006-01-06 22:22:42">
<type id="11">
note</type>
<author id="387687">
sk</author>
<data>
<field name="doctext">
[Tanktalus]'s suggestion is a better to handle this problem. But if you want something quick and dirty, you can do something like this - &lt;p&gt;

&lt;c&gt;
#!/usr/bin/perl -w

use strict;

my $base = "ca";

my @dirs = map { $base . int (rand 100) } (1..10);

# Instead of matching for $base (ca) you can also match characters etc. This approach works for simple things and can get complex quickly
my @sorted = sort { $a-&gt;[0] cmp $b-&gt;[0] ||
                    $a-&gt;[1] &lt;=&gt; $b-&gt;[1] } map { [/($base)(\d+)/] } @dirs;

@sorted = map { $_-&gt;[0] . $_-&gt;[1] } @sorted;

print $_, $/ for (@dirs);
print $/;
print $_, $/ for (@sorted);

&lt;/c&gt;
&lt;p&gt;
Output&lt;p&gt;
&lt;c&gt;
ca58
ca43
ca98
ca83
ca11
ca59
ca54
ca92
ca69
ca30

ca11
ca30
ca43
ca54
ca58
ca59
ca69
ca83
ca92
ca98
&lt;/c&gt;</field>
<field name="root_node">
521694</field>
<field name="parent_node">
521694</field>
</data>
</node>
