Skip to content

Instantly share code, notes, and snippets.

@note103
Last active December 27, 2015 00:59
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/7241971 to your computer and use it in GitHub Desktop.
Save note103/7241971 to your computer and use it in GitHub Desktop.
Perl入学式in東京vol.3の復習問題「score.pl」より 第3問『五段階評価』。
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
binmode STDOUT, ":utf8";
#ここからしばらく素材データ。
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 @people = ($papix, $boolfool, $moznion, $binarian, $uzulla);
my @lang = qw(perl python ruby php binary);
for my $people(@people) {
print "$people->{name}: \n";
for my $lang (@lang) {
my $num = $people->{$lang};
my $rate;
if ($num == 100) {
$rate = "★★★★★";
} elsif ($num <= 99 && $num >= 80) {
$rate = "★★★★";
} elsif ($num <= 79 && $num >= 60) {
$rate = "★★★";
} elsif ($num <= 59 && $num >= 40) {
$rate = "★★";
} elsif ($num <= 39 && $num >= 20) {
$rate = "★";
} else {
$rate = "";
}
print " $lang: $rate\n";
}
}
@note103
Copy link
Author

note103 commented Oct 30, 2013

設問:URL

 0 - 19 =>
20 - 39 => ★
40 - 59 => ★★
60 - 79 => ★★★
80 - 99 => ★★★★
100     => ★★★★★
----
boolfool:
perl: ★★
python:
ruby: ★
php:
binary:
  • それぞれの人物の言語毎の成績を上記を参考に5段階表示して出力して下さい
  • 全角文字を出力するので冒頭にbinmode STDOUT, ":utf8";と書いておくとよいでしょう

@note103
Copy link
Author

note103 commented Oct 31, 2013

設問のところに「冒頭にbinmode STDOUT, ":utf8";と書いておくとよいでしょう」とあったのを忘れていたので
use utf8;
と合わせて追加しておいた。

  • use utf8; ナシで実行したら文字化けしたので。
  • use utf8; binmode STDOUT, ":utf8"; なくてもとくに問題はなかったが。

@note103
Copy link
Author

note103 commented Oct 31, 2013

@risou
Copy link

risou commented Nov 1, 2013

細かいところで恐縮ですが。
64行目からのifで、どの条件に入っても改行が挿入されているのは、
77行目を

print "    $lang: $rate\n";

とした方が良い気がしますね。
あと、77行目、インデントが1つ足りてないように見えます(動作上問題はありません)。

@note103
Copy link
Author

note103 commented Nov 2, 2013

ありがとうございます!!
ご指摘大変ありがたいです!!
のちほど確認して反映したいと思いますが、パッと想像してみるだけでも本当にそうだと思いました。
(改行が繰り返されているなんて、まったく気づいていませんでした)

@note103
Copy link
Author

note103 commented Nov 2, 2013

修正しました! 動作も問題ありませんでした。

インデントは最後に崩れを直しているときに、その部分で少しどうすればいいのか迷ったのですが、ご指摘に沿ってやってみたら随分すっきりしました。他のファイルも同様の観点で見なおしてみたいと思います。

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