in reply to Sorting Issue
You need to sort the two columns independently then put them back together. Note that the following code assumes that both columns contain the same number of entries:
use warnings; use strict; my @firsts; my @seconds; while(<DATA>) { chomp; my($val1,$val2) = split /,/; push @firsts, $val1; push @seconds, $val2; } @firsts = sort {$a <=> $b} @firsts; @seconds = sort {$a <=> $b} @seconds; my @sorted; push @sorted, [$firsts[$_], $seconds[$_]] for 0..$#firsts; print "$_->[0], $_->[1]\n" for @sorted; __DATA__ 10,20 30,10 20,70 70,80 40,90 90,100 50,50
Prints:
10, 10 20, 20 30, 50 40, 70 50, 80 70, 90 90, 100
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |