develooper Front page | perl.beginners | Postings from February 2009

picking largest key by value..

Thread Next
From:
Rick
Date:
February 26, 2009 12:34
Subject:
picking largest key by value..
Message ID:
49A6FCC3.6000006@gmail.com
trying out getting lasrgest key(by value) but below is not working...

help please.

my %files=%{{"one" =>"1", "thiry" =>"30", "four" =>"4", "never" =>"997", 
"forever" =>"100001", "five" =>"5"}};
my $max;
print join(" ",keys %files),"\n";

=pod
grep($max=($files{$_} > $max )? $_ : $max,keys %files);
=cut
for my $jot (keys %files) {
        print "$jot $files{$jot}\n";
}

for my $now (keys %files) {
       $max = $now if $now > $max;       
}
    

print "<$max>\n";

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About