http://qs1969.pair.com?node_id=561634

farhan has asked for the wisdom of the Perl Monks concerning the following question:

I have comma separated CSV file. And there are 5 columns date,delta time, bits, bitsin, bitsout.
Task is
1) sort the file by date
2) ignore the bits
3) compare the bitsin and bitsout and keep the highest one
4) sort the higest one
5) print all above four steps comma separated
I have done first 3 steps and i dont know how i can perform step 4 any body can help me

Raw Data File Contents
12/6/2006 00:02:23,301,1151.78735352,677.26245117,474.52490234
12/6/2006 00:07:22,299,1108.97656250,641.49835205,467.47827148
12/6/2006 00:12:22,300,1020.15997314,590.40002441,429.76000977
12/6/2006 00:17:23,301,981.26245117,562.01995850,419.24252319

OutPut File
1/6/2006 00:03:46 300,641.06665039,477.60000610,641.06665039
1/6/2006 00:08:46 300,563.78668213,425.60000610,563.78668213
1/6/2006 00:13:47 301,505.99334717,430.72424316,505.99334717

Wanting Output

1/6/2006 00:03:46 300,641.06665039,477.60000610,641.06665039 ,505.99334717
1/6/2006 00:08:46 300,563.78668213,425.60000610,563.78668213 ,563.78668213
1/6/2006 00:13:47 301,505.99334717,430.72424316,505.99334717 ,641.06665039

open(RAW,"raw_data") or die ("could not open the file $!"); while(<RAW>) { chomp; next if /^(\s)*$/; my @this_record = split(/,/,$_); push(@records,\@this_record); } my @sorted = sort{$a->[0] <=> $b->[0]} @records; foreach $record (@sorted) { if($record->[3] >= $record->[4]) { $final = $record->[3]; } else { $final = $record->[4]; } print "$record->[0] $record->[1],$record->[3],$record->[4],$final\n"; } close(RAW);

2006-07-17 Retitled by Corion, as per Monastery guidelines
Original title: 'Sorting'