我正在尝试遍历每个文件夹中的文件并从该文件中获取信息并将其更新为数组 For ex。
use File::Find;
sub main
{
my @names = ();
my $dir = "mydir";
# will traverse directories and look for file 'list.txt'
### now, is it possible to update @names while traversing using find?
find(\&getNames(), $dir);
}
sub getNames
{
#I tried to take names as argument but it doesn't seem to work..
if (-f $_ && $_ eq 'list.txt')
{
#update names possible?
}
}
使用 File::Find 遍历时是否可以更新数据结构?而且我试图不使用全局变量..