Ask a Question related to PERL Beginners, Design and Development.
-
David Byrne #1
XML parse - hash of hashes
Greetings,
I am fairly new to Perl and to XML and I’m trying to
(1) parse a XML document (snippet attached), (2)
update specified data using a hash of hashes parsed
from another non-XML document (not shown), and then
(3) write the updated data using the XML format of the
original file in #1.
Using XML::Simple, I’ve parsed the attached file into
deeply nested anonymous hashes. I’m having trouble
trying to figure out how to iteratively traverse this
tree and update specific values using the hash of
hashes, instead of updating individually specified
values (example shown below). How can I create a loop
to do this?
Below is my current script:
################################################## ##
#!perl
#
use strict;
use warnings;
use XML::Simple;
open (OUTPUT,">out.txt") || die "Sorry, couldn't open
OUTPUT file: $!";
my $config = XMLin('input.xml',forcearray=>1);
$config->{TSCHierarchyClusterData}->[0]->{Root}->[0]->{Child}->[0]->{Child}->[0]->{Child}->[1]->{Child}->[0]->{Child}->[0]->{ClusterNum}="3333";
# This is an example of modifying an individual value.
# But I'm looking for an easier way to say "update
cluster number 365 with 3333" while looping through a
hash of hashes, instead of having to write out the
whole reference each time.
print OUTPUT XMLout($config,xmldecl=>'<?xml
version="1.0"?>');
################################################## ##
Thanks for any help that you can provide,
David
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
[url]http://webhosting.yahoo.com/ps/sb/[/url]
David Byrne Guest
-
hash of hashes
Hi all. How can I create $Subject for future population? -- Yours truly, WBR, Paul Argentoff. Jabber: paul@jabber.rtelekom.ru RIPE: PA1291-RIPE -
Sorting Hash of Hashes with HEAP module
Hi, I would like to use the Heap module from CPAN to sort Hash of Hashes by values, keeping track of what pairs of keys belong to what values. ... -
Accesing hash of hashes
Hello: I am trying to create and access a multidimensional hash. For example the following works ====== $route {$routeDest} = $cost ; print... -
Sort a hash based on values in the hash stored as arrays of hashes
Hmm. I'm not quite sure if I got the subject right, but I'll try to explain. :-) I've got a hash of elements stored like this: $VAR1 = {... -
iterating through hash of hashes
I'd like to iterate through a hash of hashes and get all the values. How do I do that? The following works for me. But it seems a bit convoluted...



Reply With Quote

