我想遍歷每個文件夾中的文件,並從該文件獲取信息並將其更新到數組 例如。perl,使用File :: Find可以修改該函數之外的數據結構嗎?
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遍歷時更新數據結構? 而我試圖不使用全局變量..
這應該是'$ names_ref'而不是'subname getNames'中的'@ names'。 –
@SlavenRezic很好的接收! – Nikhil