以下是我的代码:
foreach my $node (@switch_list) {
chomp $node;
print "$node \n";
my $f3 = ">$node.txt";
chmod 0755, $f3;
open FILE3, "$f3" or die "Could not open file:$! \n";
}
在这里,我想要创建许多具有完全权限的文件,但似乎是使用创建的文件 许可:0640而不是0755。
答案 0 :(得分:5)
你在做:
my $f3 = ">$node.txt";
chmod 0755, $f3;
因此Perl会查找名为>$node.txt
的文件。
取而代之的是:
my $f3 = "$node.txt";
chmod 0755, $f3;
open FILE3, ">", "$f3" or die "Could not open file:$! \n";
答案 1 :(得分:0)
codaddict是正确的,因为您已在$f3
字符串中包含该模式,这可能会导致chmod
失败。
但是,使用chmod
比使用open
更好的解决方案可能是使用umask
,我认为sysopen
可以使用{{1}}(尽管文档只提到了{{1}},我不在linux中,所以我可以尝试一下。)