読者です 読者をやめる 読者になる 読者になる

Perl入学式 #2 復習問題 score.pl

Perl
#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
my $papix = {
    name        => 'papix',
    affiliation => 'namba.pm',
    perl        => 60,
    python      => 50,
    ruby        => 50,
    php         => 80,
    binary      => 30,
};
my $boolfool = {
    name        => 'boolfool',
    affiliation => 'namba.pm',
    perl        => 40,
    python      => 10,
    ruby        => 20,
    php         => 30,
    binary      => 10,
};
my $moznion = {
    name        => 'moznion',
    affiliation => 'hachioji.pm',
    perl        => 100,
    python      => 70,
    ruby        => 80,
    php         => 50,
    binary      => 50,
};
my $binarian = {
    name        => 'binarian',
    affiliation => 'hachioji.pm',
    perl        => 10,
    python      => 11,
    ruby        => 1,
    php         => 100,
    binary      => 100,
};
my $uzulla = {
    name        => 'uzulla',
    affiliation => 'hachioji.pm',
    perl        => 1,
    python      => 0.01,
    ruby        => 0.5,
    php         => 4,
    binary      => 0.01,
};
my @name = ($papix,$boolfool,$moznion,$binarian,$uzulla);
my @lang = ('perl','python','ruby','php','binary');
my $sum_perl=0;
my $sum_python=0;
my $sum_ruby=0;
my $sum_php=0;
my $sum_bin=0;
for my $name (@name){
#       print Dumper $name->{perl};
        $sum_perl   = $sum_perl + $name->{perl};
        $sum_python = $sum_python + $name->{python};
        $sum_ruby   = $sum_ruby   + $name->{ruby};
        $sum_php    = $sum_php    + $name->{php};
        $sum_bin    = $sum_bin    + $name->{binary};
}
print "$sum_perl\n";
print "$sum_python\n";
print "$sum_ruby\n";
print "$sum_php\n";
print "$sum_bin\n";

for my $name (@name){
        print "-----------------------\n";
        print "$name->{name}:\n";
        for my $lang (@lang){
                print "$lang:";
                for my $num (1..$name->{$lang}/20){
                        print '★';
                };
                print "\n";
        };
};

# 4.所属ごとのperlのスコアが60以上の人の名前を格納する
my $highscore={};
my $tmp=0;
for my $name (@name){
        for my $lang (@lang){
                #print $name->{$lang};
                if($name->{$lang} >= 60 ){
                        push @{$highscore->{$lang}},$name->{name};
                }
        };
};
print "---------------------------------------------\n";
for my $lang (@lang){
        print "$lang- @{$highscore->{$lang}}\n";
}