Skip to content

Instantly share code, notes, and snippets.

@note103
Last active December 27, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save note103/7253246 to your computer and use it in GitHub Desktop.
Save note103/7253246 to your computer and use it in GitHub Desktop.
Perl入学式in東京vol.3の復習問題「score.pl」より 第4問『所属毎の スコアが 60 以上の人の名前を格納する』。
#!/usr/bin/env perl
use strict;
use warnings;
use DDP;
my $papix = {
name => 'papix',
affiliation => 'namba.pm',
perl => 60,
python => 50,
ruby => 50,
php => 80,
binary => 30,
sum => 270,
};
my $boolfool = {
name => 'boolfool',
affiliation => 'namba.pm',
perl => 40,
python => 10,
ruby => 20,
php => 30,
binary => 10,
sum => 110,
};
my $moznion = {
name => 'moznion',
affiliation => 'hachioji.pm',
perl => 100,
python => 70,
ruby => 80,
php => 50,
binary => 50,
sum => 350,
};
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 @people = ($papix, $boolfool, $moznion, $binarian, $uzulla);
my (@perl, @python, @ruby, @php, @binary);
my ($people, $name);
for $people (@people) {
if (($people->{perl})>= 60) {
push @perl, $people->{name};
}
if (($people->{python})>= 60) {
push @python, $people->{name};
}
if (($people->{ruby})>= 60) {
push @ruby, $people->{name};
}
if (($people->{php})>= 60) {
push @php, $people->{name};
}
if (($people->{binary})>= 60) {
push @binary, $people->{name};
}
}
my $highscore = {
perl => "@perl",
python => "@python",
ruby => "@ruby",
php => "@php",
binary => "@binary",
};
p $highscore;
@note103
Copy link
Author

note103 commented Oct 31, 2013

設問:URL

`$highscore` と言ったハッシュリファレンスを用意し、所属毎に優秀な人物の名前を push して下さい
`$highscore` における key を所属として配列のリファレンスにするのがいいですね

@note103
Copy link
Author

note103 commented Oct 31, 2013

実行結果:

\ {
    binary   "binarian",
    perl     "papix moznion",
    php      "papix binarian",
    python   "moznion",
    ruby     "moznion"
}

@note103
Copy link
Author

note103 commented Oct 31, 2013

関連URL:

@note103
Copy link
Author

note103 commented Oct 31, 2013

さすがにもうちょっと何とかなりそうな気はする・・

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment