in reply to HOWTO XML::Simple
use strict; use warnings; use XML::Simple; my $xs = XML::Simple->new(ForceArray=>['httpd']); my $s = do { local $/=undef; <DATA> }; my $conf = $xs->XMLin($s); my $ct = 0; foreach my $httpd ( @{$conf->{httpd}} ){ $ct++; if( ref($httpd) eq 'HASH' ){ $httpd->{number} = $ct; }else{ $httpd = { content=>$httpd, number=>$ct }; } } my $xml = $xs->XMLout($conf); print $xml; __DATA__ <x> <httpd><![CDATA[ ...1st piece of httpd configuration ]]></httpd> <httpd><![CDATA[ ...2nd piece of httpd configuration ]]></httpd> </x>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HOWTO XML::Simple
by mirod (Canon) on Oct 21, 2005 at 12:27 UTC | |
|
Re^2: HOWTO XML::Simple
by pajout (Curate) on Oct 21, 2005 at 13:45 UTC |