숫자를 한개 입력하여, 그 수의 절대치를 출력한다. 이것의 입력이 없어질때까지 반복시킨다.
use strict;
use warnings;
my $str;
while (1) {
print "Please enter the number.(Enter exit at the end) ";
$str = <STDIN>;
chomp $str;
if ($str eq "exit" || $str eq "") {
last;
}
if ($str =~ /[a-zA-Z]/) {
print "Not number.\n";
next;
}
print (abs($str), "\n");
};
'Perl' 카테고리의 다른 글
[Perl]for, if (0) | 2014.11.19 |
---|---|
[Perl]if 비교기호 (0) | 2014.11.19 |
[Perl]For, Foreach (0) | 2014.11.19 |
[Perl]배열 (0) | 2014.11.18 |
[Perl]홀수, 짝수 구하기 (0) | 2014.11.18 |