in reply to problem parsing XML into hash
You also don't say what's wrong with the output, which makes is hard to guess what the correct out put should be.
Anyway, if you're intent on hacking this, the following code give the output as described. Is this what you're after?
(PS. Could you change the title to something more searchable like 'problem parsing xml into a hash?')
while (my $str = <DATA>) { chomp($str); $comp = $1 if $str =~ m{<COMP_NAME>(.*?)</COMP_NAME>}; $cmd = $1 if $str =~ m{<CCC_NAME>(.*?)</CCC_NAME>}; if ($str =~ m{<TC_LOC>(.*?)</TC_LOC>}) { $hoh{$comp}{$cmd}{$1} = undef; } } print Dumper \%hoh; __OUTPUT__ $VAR1 = { 'ip' => { 'ip1' => { '/tftpboot/tc1' => undef }, 'ip2' => { '/tftpboot/tc3' => undef, '/tftpboot/tc4' => undef, '/tftpboot/tc1' => undef } }, 'parser' => { 'p2' => { '/tftpboot/tc1' => undef }, 'p3' => { '/tftpboot/tc2' => undef, '/tftpboot/tc3' => undef, '/tftpboot/tc1' => undef }, 'p1' => { '/tftpboot/tc2' => undef, '/tftpboot/tc1' => undef } } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: error in my code
by rsennat (Beadle) on Nov 23, 2005 at 12:00 UTC | |
by reasonablekeith (Deacon) on Nov 23, 2005 at 12:08 UTC | |
by rsennat (Beadle) on Nov 23, 2005 at 12:24 UTC |