1
我知道我可以使用require並以不同的方式來完成此操作,但我只是在perl周圍忙碌着,遇到了一些我不知道如何解釋的東西。通過系統調用從其他perl腳本獲取結果
這是我的第一個劇本:
use 5.16.2;
use warnings;
sub get
{
print "hello";
}
get();
測試腳本:
use 5.16.2;
use warnings;
my $val=system('perl test.pl');
print "$val\n";
#prints: hello0, I surmised that 0 is the return code for system
我擡頭怎麼不理0和得到的東西,這是錯的,但使我這個:
print '', system('perl test.pl');
#also prints hello0
my $val='', system('perl test.pl');
print "$val\n";
#prints: hello
這可行,但我完全不知道爲什麼。我也很困惑,爲什麼之前的那個不工作。有人能解釋一下嗎?
謝謝。這很有道理。 – 2013-05-14 05:30:48
@SteveP .:不客氣! – ruakh 2013-05-14 06:13:22