我在某个目录中有一些xml文件,因此我正在该目录中搜索所需的xml文件,并使用下面的脚本将哈希数据结构中的xml数据存储。但我的问题是我需要保存在散列每个XML文件的文件路径,但任何一个可以帮助我如何使用上面的脚本我保存文件路径散列数据 我写这样的脚本如何使用Perl将xml路径包含到哈希中
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
use Carp;
use File::Find;
use File::Spec::Functions qw(canonpath);
use Data::Dumper;
my @ARGV ="C:/Main/work"; die "Need directories\n" unless @ARGV;
find(
sub {
return unless (/(_service\.xml)$/ and -f);
Hash_information();
return;
},
@ARGV
);
sub Hash_information {
my $path= $_;
my $xml = new XML::Simple;
my $data = $xml->XMLin("$path", ForceArray => [
'Service','SystemReaction','SW','HW','Component' , 'BM'],
KeyAttr=>{Service=>'Id'} );
print Dumper ($data);
return;
}
获取所有服务xml文件的表单文件夹并使用XML :: Simple存储在散列数据结构中。现在我想保存散列数据结构中每个xml文件的文件路径。谁能帮我。
在此先感谢
ps。你可以在`sub`末尾放弃一个裸体`return'...但是你不是想要返回'$ data`还是将它存储在某个地方? – BRFennPocock 2011-12-14 18:05:36