http://seungngil.tistory.com/entry/Perlfor-if에서, 입력하는 숫자를 10개가 아닌, 입력이 없어질때까지로 할것. 또한, while문, for문, if문은 각각 하나씩 사용하게된다.
use strict;
use warnings;
my $num;
my $result;
my @array = (2, 3, 4, 5, 6);
for (;;) {
print ("Please enter the number.(Enter exit at the end) ");
$num = <STDIN>;
chomp $num;
if ($num =~ /[a-zA-Z]/ || $num eq "") {
exit;
}
$result = ($num . " = ");
my $j = 0;
while ($j < scalar(@array)) {
$result .= ("[" . $array[$j] . "]" . (($num % $array[$j]) == 0 ? "OK" : "NG"));
$j++;
}
$result .= "\n";
print ($result);
}
'Perl' 카테고리의 다른 글
[Perl] Subroutine parameter (0) | 2014.12.19 |
---|---|
[Perl] Subroutine (0) | 2014.12.19 |
[Perl]for, if (0) | 2014.11.19 |
[Perl]if 비교기호 (0) | 2014.11.19 |
[Perl]For, Foreach (0) | 2014.11.19 |