如何使用perl将xml路径包含到哈希中

ver*_*dra 1 xml perl

我在目录中有一些xml文件,因此我在该目录中搜索所需的xml文件,并使用下面的脚本将xml数据存储在哈希数据结构中.但我的问题是我需要在散列中保存每个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;
  }
Run Code Online (Sandbox Code Playgroud)

使用上面的脚本我得到所有服务xml文件表单文件夹并使用XML :: Simple存储在哈希数据结构中.现在我想在散列数据结构中保存每个xml文件的文件路径.谁能帮我.
提前致谢

JRF*_*son 5

在File :: Find的子例程中,$ File :: Find :: name是完整的路径名.将其传递给您的Hash_information子例程.

...
find(
    sub {
        return unless ( /(_service\.xml)$/ and -f );
        Hash_information($File::Find::name);
...
sub Hash_information {
my ($path) = @_;
...
Run Code Online (Sandbox Code Playgroud)