!/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"; } }
总结以上是内存溢出为你收集整理的perl 小练习全部内容,希望文章能够帮你解决perl 小练习所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)