in reply to Re: Sort an array of strings based on two fields
in thread Sort an array of strings based on two fields
or would it be ok to insert the missing zero?my @sorted = sort { ($a =~ /\.([0-9]+)-([0-9]+)\./, 100*$1+$2) <=> ($b =~ /\.([0-9]+)-([0-9]+)\./, 100*$1+$2) } @strings;
(Make sure the regexp does not match elsewhere in your strings.)map { s/-(\d)\./-0\1./ } @strings; my @sorted = sort @strings;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sort an array of strings based on two fields
by choroba (Cardinal) on Mar 14, 2013 at 10:55 UTC |