my @hex_locations = ("$FindBin::Bin/../../../project/platform-fsm9900_cdp-full/build-target/gnss-1.0.0",
"$FindBin::Bin/../../../project/platform-fsm9900_cdp-base/build-target/gnss-1.0.0");
而不是这两行,我可以使用通配符在单行中指定它,如下所示吗? “$ FindBin ::彬/../../../项目/平台fsm9900_cdp - * /编译目标/ GNSS-1.0.0”
my @hex_dep_files;
sub find_dep_files {
my $F = $File::Find::name;
if ($F =~ /.d$/ ) {
push(@hex_dep_files,$F)
}
}
for my $loc (@hex_locations) {
find({ wanted => \&find_dep_files, no_chdir=>1}, $loc);
}
使用上面的for循环,我从@hex_locations获取所有* .d文件,我可以在单个函数中执行它而不是调用一个名为“find_dep_files”的单独函数,我不想调用另一个函数从这个for循环,所以我不需要将数组@hex_dep_files定义为全局。
感谢您的帮助。
答案 0 :(得分:2)
你不能只使用glob:
my @files = </path/to/files/*.extension>;
答案 1 :(得分:2)
回答实际问题。
my @hex_dep_files;
for my $loc (@hex_locations) {
find({
no_chdir => 1,
wanted => sub {
my $F = $File::Find::name;
return if $F !~ /.d$/;
push @hex_dep_files, $F;
},
}, $loc);
}
或
my @hex_dep_files;
find({
no_chdir => 1,
wanted => sub {
my $F = $File::Find::name;
return if $F !~ /.d$/;
push @hex_dep_files, $F;
},
}, @hex_locations);