On 2/26/09 Thu Feb 26, 2009 12:34 PM, "Rick" <rich.j...@gmail.com> scribbled:
> 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; > } You want to compare values and save keys. You might also want to avoid comparing an undefined value: my $max; for my $now ( keys %files ) { if( defined $max ) { $max = $now if $files{$max} > $files{$now}; }else{ $max = $now; } } > > > print "<$max>\n"; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/