我正在尝试实现一个过程,该过程遍历目录中的所有subdirectories
内容,在.root
.xml
Perl
sub getXMLFiles {
my $current_dir = $_[ 0 ];
opendir my $dir, $current_dir or die "Cannot open directory: $!\n";
my @files = grep /\.xml$/i, readdir $dir;
closedir $dir;
return @files;
}
sub iterateDir {
my $current_dir = $_[ 0 ];
finddepth( \&wanted, $current_dir );
sub wanted{ print getXMLFiles }
}
#########################################################
# #
# define the main subroutine. #
# first, it figures from where it is being ran #
# then recursively iterates over all the subdirectories #
# looking for .xml files to be reformatted #
# #
#########################################################
sub main(){
#
# get the current directory in which is the
# program running on
#
my $current_dir = getcwd;
iterateDir( $current_dir );
}
#########################################################
# #
# call the main function of the program #
# #
#########################################################
main();
我不是很熟悉Perl
。该sub iterateDir
过程应该遍历子目录,而getXMLFiles
将过滤.xml
文件并返回它们。我会使用这些.xml
文件进行解析。这就是为什么我试图.xml
从一个root
目录中找到所有文件。但是,我不知道如何使用sub wanted
里面的程序iterateDir
发送dirpath
to getXMLFiles
。我怎么能做到这一点?