我無法從$ File :: Find :: name獲取文件的絕對路徑。它顯示undef谷值作爲輸出。無法弄清楚,爲什麼:(任何一個可以請幫我在顯示此
錯誤是:使用未初始化值$ FILE_NAME的級聯
我的代碼:
use strict;
use warnings;
use File::Find;
use File::Path qw(make_path);
use File::Copy;
use Cwd;
use Data::Printer;
my $rootPATH = $ARGV[0];
my $id = $ARGV[1];
my @Arraypath;
my $file_name;
our $anr_name;
opendir(my $DIR, $rootPATH);
while (my $entry = readdir $DIR) {
next unless -d $rootPATH . '/' . $entry;
next if $entry eq '.' or $entry eq '..';
#print "Found directory $entry\n";
push(@Arraypath, (split("\n", $entry)));
}
closedir $DIR;
my $count = 0;
foreach my $line (@Arraypath) {
my $fulllogpath = $rootPATH . "\\" . $line;
#print "$fulllogpath\n";
$count++;
start($fulllogpath);
}
sub start {
my $fulllogpath = shift;
our @content;
#print "$fulllogpath\n\n";
find(\&wanted, $fulllogpath);
sub wanted {
push @content, $_;
return;
}
foreach my $file (@content) {
# print "$file\n\n";
if ($file =~ /traces[_d]*/) {
print "$file\n\n";
$file_name = $File::Find::name;
p $file_name;
print "$file_name\n";
}
}
}
'$文件::查找:: name'纔有效在'wanted'函數中。不在其外面。 – dgw 2014-09-02 11:18:18
是否有任何其他方式來獲取文件的絕對路徑? – user1362796 2014-09-02 11:20:13
您可以在'wanted'子文件中存儲完整路徑。將'$ _'更改爲'$ File :: Find :: name'。雖然可能有更適合這個工作的模塊。 – TLP 2014-09-02 12:32:26