So, the next step was to find the row corresponding to max score, I wrote something like this. This gets me per year wise what is the max score but I am unable to fetch the index of the calculated max so that I can use that to print the corresponding values in column 1.
For example: if for the year 1901 score2 is max, then I want to print
a2 1901 score2
But with my current code I can only print
1901 score2
use strict;
use warnings;
use List::Util qw( min max );
use Data::Dumper;
my $file=shift;
open (DATA, $file);
my %h1;
my @tmp;
my $max_value;
my $a;
my $b;
while (my $line = <DATA>) {
chomp $line;
my ($val, $year, $score) = split /\s+/, $line;
push @{$h1{$year}}, $val;
push @{$h1{$year}}, $score;
}
foreach my $x (sort keys %h1)
{
foreach (@{$h1{$x}})
{
if ($_=~/^[0-9]/)
{
push @tmp, $_;
}
$max_value= max @tmp;
}
print "$x\t$max_value\n";
}
print Dumper \%h1;