我写了以下的Perl脚本,但问题是它总是进入else分支并报告不是文件。我在输入中给出的目录中确实有文件。我在这里做错了什么?
我的要求是递归地访问目录中的每个文件,打开它并将其读取到一个字符串中。但是逻辑的第一部分失败了。
我的要求是递归地访问目录中的每个文件,打开它并将其读取到一个字符串中。但是逻辑的第一部分失败了。
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Find;
my (@dir) = @ARGV;
find(\&process_file,@dir);
sub process_file {
#print $File::Find::name."\n";
my $filename = $File::Find::name;
if( -f $filename) {
print " This is a file :$filename \n";
} else {
print " This is not file :$filename \n";
}
}
which
的版本,你只需要perl --version
或者perl -V
,或者如果perl
不在你的PATH
中,也许是$(which perl) --version
或者$(which perl) -V
。 - mu is too short