perl 小练习

前端之家收集整理的这篇文章主要介绍了perl 小练习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

!/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相关文章