<policies> <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" /> <policies2 name="General Admit to GPRMC" catagory="General" description="" link_name="General Admit to GPRMC.doc" /> </policies>
use strict; my $xs = new XML::Simple; my $xml = $xs->XMLin("$folder_path\\policies.xml", forcearray => 1, ke +yattr => ['policies']); my $hash_add = [{ $cat => [{ 'name' => "$name", 'link_name' => "$link_name", 'description' => "$desc", 'date' => "$today_date" }] }]; # Add to hash push (@{$xml->{'policies'}}, $hash_add); 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 => "$folder_path\\policies.xml", attrinde +nt => 1);
'policies' => [ { 'New' => [ { 'date' => '28-8-104', 'name' => 'Test3', 'link_name' => 'Test3.doc', 'description' => 'asdf' } ], 'policies2' => [ { 'name' => 'General Admit +to GPRMC', 'link_name' => 'General A +dmit to GPRMC.doc', 'description' => '', 'catagory' => 'General' } ], 'Newer' => [ { 'date' => '28-8-104', 'name' => 'Whatever', 'link_name' => 'Whatever.doc' +, 'description' => 'asdf' } ] }, [ { 'Newer' => { 'date' => '28-8-104', 'name' => 'whatever', 'description' => 'something +', 'link_name' => 'whatever.do +c' } } ] ]
<policies> <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" /> <policies2 name="General Admit to GPRMC" catagory="General" description="" link_name="General Admit to GPRMC.doc" /> </policies> <policies> <anon name="whatever" date="28-8-104" description="something" link_name="whatever.doc" /> </policies>
In reply to Adding a hash to a hash reference. by bkiahg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |