in reply to Adding a hash to a hash reference.
This must be close to what you wanted (you have to observe the original data structure a little bit more carefully, see how XML::Simple use/understand things):
use strict; use XML::Simple; my $xs = new XML::Simple; my $xml = $xs->XMLin("policies.xml", forcearray => 1, keyattr => ['pol +icies']); my $policyproperties = { 'name' => "1", 'link_name' => "2", 'description' => "3", 'date' => "4" }; # Add to hash $xml->{'addedone'} = $policyproperties; print "Content-type: text/html\n\n"; # Sort hash #@{ $xml->{'policies'} } = sort { "\L$a->{name}" cmp "\L$b->{name}"} @ +{ $xml->{'policies'} }; use Data::Dumper; print Dumper($xml); $xs->XMLout($xml, outputfile => "policies1.xml", attrindent => 1);
Output:
<opt> <New name="Test3" date="28-8-104" description="asdf" link_name="Test3.doc" /> <Newer name="Whatever" date="28-8-104" description="asdf" link_name="Whatever.doc" /> <addedone name="1" date="4" description="3" link_name="2" /> <policies2 name="General Admit to GPRMC" catagory="General" description="" link_name="General Admit to GPRMC.doc" /> </opt>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding a hash to a hash reference.
by pg (Canon) on Sep 29, 2004 at 03:23 UTC | |
by bkiahg (Pilgrim) on Sep 29, 2004 at 23:13 UTC |