use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new (); my @expectedFields = qw(X Y Z Time Amplitude); # Validate the header line $csv->parse (scalar ); my @fieldNames = $csv->fields (); die "Unexpected field list: @fieldNames\nExpected: @expectedFields\n" unless @expectedFields == @fieldNames; for my $fieldIndex (0 .. $#fieldNames) { next if $fieldNames[$fieldIndex] eq $expectedFields[$fieldIndex]; die "Got field name $fieldNames[$_]. Expected $expectedFields[$fieldIndex]\n"; } # Find maximums in each 1 second slot my %maximums; # Keyed by date/time while (defined (my $line = )) { $csv->parse ($line); my ($x, $y, $z, $time, $amplitude) = $csv->fields (); $time =~ s/\.\d{3}//; # Strip fractional seconds next if exists $maximums{$time} && $maximums{$time}{amp} >= $amplitude; $maximums{$time}{amp} = $amplitude; $maximums{$time}{line} = $line; } # Output results ordered by time assuming the same date print $maximums{$_}{line} for sort keys %maximums; __DATA__ X,Y,Z,Time,Amplitude 2550,531,66,10-12-2007 07:03:08.069,2 2549,529,62,10-12-2007 07:03:08.151,1 2550,531,66,10-12-2007 07:03:09.069,1 2549,529,62,10-12-2007 07:03:09.151,2 #### 2550,531,66,10-12-2007 07:03:08.069,2 2549,529,62,10-12-2007 07:03:09.151,2