in reply to numeric sort on substring
I'm trying to sort on the first two columns
sub RowSort { my($a1, $a2) = $a =~ /(\d+),(\d+)/; my($b1, $b2) = $b =~ /(\d+),(\d+)/; $a2 <=> $b2 or $a1 <=> $b1; }
Chaining comparisons with 'or' has the effect that if the first one says 'equal' (<=> yields 0), the next comparison is being tested, etc.
|
|---|