I have some xml files in a directory , so I am searching required xml files in that directory and storing xml data in a hash data structure using below script. But my problem is I need to save the file path of each xml file in the hash But Can any one help me how to save file path in hash data
I written script like this
#!/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;
}
using above script I am getting all service xml files form folder and using XML::Simple storing in a hash data structure. Now I want to save file path of each xml file in the hash data structure. Can any one help me.
Thanks in advance
In the subroutine for File::Find, $File::Find::name is the complete path name. Pass that to your Hash_information subroutine.