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: [jim_lad] Sorting: Edit Log



sohnaeo
Novice

Jul 18, 2006, 4:45 AM


Views: 4207
Re: [jim_lad] Sorting

Thanks for reply. If you check my code I want to sort $final .For this I need to push $final in array and then sort but it is in the While loop. If I

sort it outside the loop then how i can get the previous array values.

check the code again

open(RAW,"raw_data") or die ("could not open the file $!");

while(<RAW>) {

chomp;

next if /^(\s)*$/;

my @this_record = split(/,/,$_); //date,delta,bits,bitsin,bitsout

push(@records,\@this_record);

}

my @sorted = sort{$a->[0] <=> $b->[0]} @records; //sort date

foreach $record (@sorted) {

if($record->[3] >= $record->[4]) { //compare bitsin and bitsout and keep the highes one

$final = $record->[3];

}

else {

$final = $record->[4]; //compare bitsin and bitsout and keep the highes one

}

###Want to sort $final but it is in the loop

print "$record->[0] $record->[1],$record->[3],$record->[4],$final\n";

//print sorted date, delta, bitsin, bitsout, wanting to print sorted highest bitsin or bitsout
}

close(RAW);


(This post was edited by sohnaeo on Jul 18, 2006, 4:50 AM)


Edit Log:
Post edited by sohnaeo (Novice) on Jul 18, 2006, 4:46 AM
Post edited by sohnaeo (Novice) on Jul 18, 2006, 4:50 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