in reply to Simple sort query
Hi. Seems that you need to sort first by alpha-prefix and then numerically.
The suggestion below assumes that all items to be sorted have a format that
matches m/(\D+)(\d+)/ completely.
See also What is "Schwarzian Transform" (aka Schwartzian) and Schwartzian Transform
use strict; my @input = qw(d3 d1 d10 d2 d20 d21 a3 d100 d201 a10 a1); my @sorted = map { $_->[0] . $_->[1] } # 3) put together elems. sort { $a->[0] cmp $b->[0] # 2) sort alpha prefix || # (if equal, then) $a->[1] <=> $b->[1] } # sort numeric suffix map { m/(\D+)(\d+)/; [ $1, $2 ] } # 1) split alpa/numeric-parts @input; print join "\n", @sorted, "\n"; __END__ a1 a3 a10 d1 d2 d3 d10 d20 d21 d100 d201
|
|---|