veerubiji has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am processing xml files form folders in a directory. 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 ); extract_info(); return; }, @ARGV ); sub extract_info { my $path= $_; my $xml=XMLin($path); my $xmldata_services = $xml->{Service}; my %dataservices; for my $xmldata_service (@$xmldata_services) { my %service = ( description => $xml_service->{Des}, name => $xml_service->{Name}, num => $xml_service->{NUM}, ); $service{sw} = _maybe_list( $xmldata_service->{Customers}{Softwar +e} ); $service{hw} = _maybe_list( $xml_service->{Suppliers}{Hardware} ); $service{sw} = _maybe_list( $xml_service->{Suppliers}{Software} ); $dataservices{ $service{id} } = \%service; } print Dumper \%dataservices; } sub _maybe_list { my $maybe = shift; return ref $maybe eq 'ARRAY' ? $maybe : [$maybe]; }

I getting one error when running this code like this "Not an array Reference" at for loop line.I tried in different ways to overcome this but still same error. How to overcome this error and How to get each file path and save in a hash? I am not able to rectify this and adding file path into hash.any one help me with this.

my xml look like this

<?xml version="1.0" encoding="UTF-8"?> <Servicelist xmlns:xsi="" xsi +:noNamespaceSchemaLocation="file:///files/service.xsd"> <Service NUM="B7a" Name="temperature sensor"> <Des>It delivers actual temperature in the form ov Volts</Des> <Customers> <Software Service="ADC" Path="/main/ADCservice.xml"/> </Customers> <Suppliers> <Software Service="input" Path="/main/inputservice.xml"/> <Software Service="signal" Path="/main/signalservice.xml"/> <Hardware Type="engine" Nr="18" Servicenum="1" Path="/main/engines +ervice.xml"/> <Hardware Type="motor" Nr="7" Servicenum="1" Path="/main/motorser +vice.xml"/> <Hardware Type="supply" Nr="1" Servicenum="1" Path="/main/supplyser +vice.xml"/> </Suppliers> </Service> </Servicelist>

any help appriciated

Thanks in advance