in reply to Re: Sort problems
in thread Sort problems
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Sort problems
by johngg (Canon) on Dec 03, 2008 at 10:22 UTC | |
Re^3: Sort problems
by monarch (Priest) on Dec 04, 2008 at 03:38 UTC |