Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Compare fields in a file

by Not_a_Number (Parson)
on Feb 10, 2009 at 19:26 UTC ( #742858=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Compare fields in a file
in thread Compare fields in a file

Try this:

use strict; use warnings; my %biggest; while ( <DATA> ) { chomp; my @items = split /,/; my $coords = join ',', @items[ 0 .. 2 ]; my ( $time, $mag ) = @items[ 3, 4 ]; if ( not defined $biggest{$coords} or $mag > $biggest{$coords}->[1] +) { $biggest{$coords} = [ $time, $mag ]; } } for my $coords ( keys %biggest ) { print join( ',', $coords, join',', @{ $biggest{$coords}} ), "\n"; } __DATA__ 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:10.001,6 2550,531,66,10-12-2007 07:03:11.099,7

Output:

2550,531,66,10-12-2007 07:03:11.099,7 2549,529,62,10-12-2007 07:03:09.151,2


Comment on Re^3: Compare fields in a file
Select or Download Code
Re^4: Compare fields in a file
by honyok (Sexton) on Feb 10, 2009 at 19:44 UTC
    Thanks all. I'll try the suggestions and udate later.
    - honyok

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742858]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-08-28 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls