!/usr/bin/perl $subject={ math=>{ "mahong"=>90, "mahao"=>98, "zhangwei"=>89, "yawei"=>98 }, chinese=>{ "mahong"=>90, "mahao"=>97, "zhangwei"=>98, "yawei"=>100 },}; print "Keys of subject:\n"; foreach $key (keys %{$subject}){ print $key . "\n"; } print "Keys of math:\n"; foreach $key (keys %{$subject->{math}}){ print $key . "\n"; } print "The best grade in math:\n"; foreach $key (keys %{$subject->{math}}){ push @tmp,$subject->{math}->{$key}; } #求单科成绩最优 sub max{ my @tmp=@_; $max=$_; foreach (@tmp){ if ($max <$_){ $max = $_; } } return $max; } $max_score=&max(@tmp); #求单科成绩最优者 print $max_score. "\n"; foreach $key (keys %{$subject->{math}}){ if ($subject->{math}->{$key} == $max_score) { print $key ."is good!!!\n"; } }