[San-Diego-pm] Sort problem

Randal L. Schwartz merlyn at stonehenge.com
Mon Aug 30 19:39:23 PDT 2010

>>>>> "Joel" == Joel Fentin <joel at fentin.com> writes:

Joel> I've tried everything I can think of without success.
Joel> my @A = ('aaa10.jpg','aaa9.jpg','bbb9.jpg','bbb10.jpg');

Joel> The desired order:
Joel> aaa9.jpg
Joel> aaa10.jpg
Joel> bbb9.jpg
Joel> bbb10.jpg

Joel> Sorted first by the text. Those with the same text sorted
Joel> numerically.

my @sorted =
  map $_->[0],
  sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
  map [$_, /^(\D+)(\d+)/],

Untested, but I usually get this stuff mostly right. :)

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

More information about the San-Diego-pm mailing list