CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [sohnaeo] Sorting: Edit Log



KevinR
Veteran


Jul 20, 2006, 11:31 AM


Views: 4139
Re: [sohnaeo] Sorting

one way:


Code
use strict; 
use Data::Dumper;
my @AoA = ();
while(<DATA>){
chomp;
my($var1,$var2)=split(/,/);
push @AoA,[$var1,$var2,($var1>$var2?$var1:$var2)];
}
my @sorted_fourth = sort{$a->[2] <=> $b->[2]} @AoA;
for my $i (0..$#sorted_fourth){
$AoA[$i][3]=$sorted_fourth[$i][2];
}
print Dumper(@AoA);
__DATA__
1,11
2,12
3,1
4,13
5,14
6,15
7,16
8,6
9,17
10,5

-------------------------------------------------


(This post was edited by KevinR on Jul 20, 2006, 11:37 AM)


Edit Log:
Post edited by KevinR (Veteran) on Jul 20, 2006, 11:37 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives