in reply to Re^2: Excel and Perl
in thread Excel and Perl
Just put your data into a hash of arrays, and then loop on the compiled data using List::Util->max to determine the max value in each array.
The below snippet demonstrates what I'm talking about with the fake data you listed:
use List::Util qw(max); use strict; use warnings; my %vals; # Put Data into a Hash of Arrays while (<DATA>) { chomp; my ($key, $val) = split; push @{$vals{$key}}, $val; } for my $key (sort {$a <=> $b} keys %vals) { my $max = max @{$vals{$key}}; print "$key $max\n"; } =prints 1 4 2 7 3 10 =cut __DATA__ 1 3 1 2 1 4 2 5 2 7 3 10 3 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Excel and Perl
by kb (Initiate) on Jun 09, 2011 at 00:34 UTC | |
by wind (Priest) on Jun 09, 2011 at 01:37 UTC | |
by kb (Initiate) on Jun 09, 2011 at 02:08 UTC | |
by Tux (Canon) on Jun 09, 2011 at 06:25 UTC | |
by kb (Initiate) on Jun 09, 2011 at 14:17 UTC | |
|
Re^4: Excel and Perl
by Tux (Canon) on Jun 09, 2011 at 14:47 UTC | |
|
Re^4: Excel and Perl
by kb (Initiate) on Jun 09, 2011 at 16:34 UTC | |
by Tux (Canon) on Jun 09, 2011 at 17:47 UTC |