[완료]perl에 관한 질문입니다.

papa3721의 이미지

#!/usr/bin/perl -w
use strict;

my($arg, $s);

foreach $arg (@ARGV)
{
$s = "$arg $s";
}
print $s;

$> ./t.pl 12 34 56
Use of uninitialized value in concatenation (.) or string at ./t.pl line 8.
56 34 12

왜 에러가 발생하는지 모르겠네요.

redneval의 이미지

변수를 초기화하지 않아서 그렇습니다.

#!/usr/bin/perl -w
use strict;
my $s;
print $s;

위의 코드는 경고(warning)를 냅니다.

다음과 같이 변수에 빈 문자열을 넣어주세요.

#!/usr/bin/perl -w
use strict;
my $s = "";
print $s;

--------------------Signature--------------------
"What can change the nature of a man?"

gamdora의 이미지

$s를 초기화하지 않고 읽었기 때문입니다.

my($arg, $s) = ('', '');
로 초기화하면 됩니다.

papa3721의 이미지

..