pack q{NNa*}, m{(\d+)_(\d+)}, $_Note that packing with an 'N' specifier fails if either of the numeric fields exceeds 4294967295. An approach using sprintf (as mentioned in johngg's reply) can get around this.
>perl -wMstrict -le "my @list = qw{ a1_2 a1_1 a10_10 a2_10 a2_1 a2_2 a10_1 a10_2 a1_10 }; use constant WIDTH => 20; my @sorted = map { substr $_, WIDTH * 2 } sort map { sprintf '%0*4$d%0*4$d%s', m{(\d+)_(\d+)}, $_, WIDTH } @list; print for @sorted; " a1_1 a1_2 a1_10 a2_1 a2_2 a2_10 a10_1 a10_2 a10_10
In reply to Re^2: Sort problems
by AnomalousMonk
in thread Sort problems
by erez_ez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |