How can i do with multiple loop :$VAR1 = [ { 'eventid' => '957', 'name' => 'aaaa' }, { 'eventid' => '2667', 'name' => 'bbbb' }, { 'eventid' => '2667' 'name' => 'bbbb' }, { 'eventid' => '1503' 'name' => 'cccc' }, { 'eventid' => '1103' 'name' => 'dddd' }, { 'eventid' => '1503' 'name' => 'cccc' } ];
---application.xml#!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); my $appxpath = $xp->findnodes("//application_list/application/"); my %appid = (); foreach my $appnodeset ($appxpath->get_nodelist) { my $id = $xp->find('./@id',$appnodeset)->string_value; my $name = $xp->find('./@name',$appnodeset)->string_value; s/^\s+|\s+$//g for $id,$name; $appid{$id} = $name; } print Dumper \%appid; my $eventxml = 'events.xml'; my $evenxp = XML::XPath->new(filename => $eventxml); my $xpath = "//event/custom_attribute_list/custom_attribute[normalize- +space(name)='SLB_SSRID']/value"; my @eventrecords = (); foreach my $node ($evenxp->findnodes($xpath)) { my $ssrid = $node->string_value; $ssrid =~ s/^\s+|\s+$//g ; if ( exists $appid{$ssrid} ){ push @eventrecords, { eventid => $ssrid }; } } print Dumper \@eventrecords;
-----Events.xml<application_list> <application id="2667" external-id="EAR-AA-2667" name="aaaa"></applica +tion> <application id="1103" external-id="EAR-AA-1103" name="bbbb"></applica +tion> <application id="957" external-id="EAR-AA-957" name="cccc"></applicati +on> <application id="1250" external-id="EAR-AA-1250" name="dddd"></applica +tion> </application_list>
<event_list> <event> <name> Incident</name> <value> INC0004532345324</value> <name> SSRID</name> <value> 957</value> </event> </event_list>
In reply to multiple for loop to extract required xml nodes by snehit.ar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |