in reply to Sorting Alphanumeric Arrays
Here's one approach, using a Schwartzian Transform:
It's only merit (if any), relative to the other solutions posted, is that it illustrates a relatively general approach to this type of problem. It's most useful when the extraction of the parameter(s) to sort by (in this case, the job done by the parse sub) is costly.sub parse { my $item = shift; return [ $item, $item =~ /^(\d+)([a-zA-Z]*)/ ]; } sub sort_alphanum { $a->[ 1 ] <=> $b->[ 1 ] or $a->[ 2 ] cmp $b->[ 2 ]; } my @sorted = map $_->[ 0 ], sort sort_alphanum map parse( $_ ), @old;
the lowliest monk
|
---|