我想解析位于一个目录的子目录中的特定XML文件。出于某种原因,我收到错误说文件不存在。如果文件不存在,它应该转到下一个子目录。更改目录并获取xml文件以解析perl中的某些数据
这里是我的代码
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
my @xmlsearch = map { chomp; $_ } `ls`;
foreach my $directory (@xmlsearch) {
print "$directory \n";
chdir($directory) or die "Couldn't change to [$directory]: $!";
my @findResults = `find -name education.xml`;
foreach my $educationresults (@findResults){
print $educationresults;
my $parser = new XML::Simple;
my $data = $parser->XMLin($educationresults);
print Dumper($data);
chdir('..');
}
}
ERROR
music/gitar/education.xml
File does not exist: ./music/gitar/education.xml
为什么不使用['使用File :: Find;'](http://perldoc.perl.org/File/Find.html)? – 2012-06-08 15:25:14
您是否想要递归查找'education.xml'文件,还是仅查找这些目录? – TLP
你好,我只是想找到一个教育目录到一个目录。所以主目录是音乐,可以说10个子目录。例如吉他,钢琴,鼓。我只想在音乐/吉他或音乐/钢琴下搜索。我不想在音乐/吉他/ dir1/dir2下搜索。 – Maxyie