perl chmod帮助设置文件权限

Mah*_*esh 2 perl

以下是我的代码:

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";
}
Run Code Online (Sandbox Code Playgroud)

在这里,我想创建许多具有完全权限的文件,但似乎是使用权限创建的文件:0640而不是0755.

cod*_*ict 5

你在做:

my $f3 = ">$node.txt";
chmod 0755, $f3;
Run Code Online (Sandbox Code Playgroud)

所以Perl会查找一个名为的文件>$node.txt.

相反:

my $f3 = "$node.txt";
chmod 0755, $f3;
open FILE3, ">", "$f3" or die "Could not open file:$! \n";
Run Code Online (Sandbox Code Playgroud)