以下是代码
use strict;
use warnings;
my $cmd = "ls";
my $pid = open(INPUT,"$cmd 2>&1 |");
print "PID = [$pid] [$?]\n";
if (!defined($pid)) {
print "PID not defined\n";
} else {
print "BEFORE CLOSING exit code is [$?]\n";
}
close INPUT;
print "AFTER CLOSING [$?]\n";
输出如下:
PID = [32300] [0]
BEFORE CLOSING exit code is [0]
AFTER CLOSING [13]
为什么是美元的价值?调用 close() 后发生变化?