#!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; 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 ; push @eventrecords, { eventid => $ssrid }; } @eventrecords = sort{ $b->{eventid} <=> $a->{eventid} } @eventrecords; + #Sorting my $index; my @recordcount; for (@eventrecords) { $index++; push @recordcount, { line => $index }; } splice @eventrecords, $index, 0, @recordcount; print Dumper \@eventrecords;
$VAR1 = [ { 'eventid' => 2667 }, { 'eventid' => 2666 }, { 'eventid' => 2656 }, { 'line' => 1 }, { 'line' => 2 }, { 'line' => 3 ];
expected code
$VAR1 = [ { 'eventid' => 2667 'line' => 1 }, { 'eventid' => 2666 'line' => 2 }, { 'eventid' => 2656 'line' => 3 }, ];
In reply to Re^12: Compare 2 XML files
by snehit.ar
in thread Compare 2 XML files
by snehit.ar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |