in reply to how do I sort numerically on sections of data that is alphanumeric
Sorts can be placed in sub-routines to make your code simpler to read.
$a and $b are special sort vars. Read this for more info. <=> compares strings numerically. If they are the same, it returns '0'.
|| (or) only goes to the second comparison if the first is zero.
So, if you're sure the data is consistant:
my @sorted_array = sort { sort_me(); } @array; sub sort_me { # get 2nd and 3rd nums my ($a_2,$a_3) = ($a =~ /A (\d+) A(\d+)/); my ($b_2,$b_3) = ($b =~ /A (\d+) A(\d+)/); # sort by second nums. If same, sort by 3rd $a_2 <=> $b_2 || $a_3 <=> $b_3; }
cLive ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: how do I sort numerically on sections of data that is alphanumeric
by bikeNomad (Priest) on Jun 27, 2001 at 00:55 UTC |