rsennat has asked for the wisdom of the Perl Monks concerning the following question:
<CCCMAP> <COMPONENT> <COMP_NAME>ip</COMP_NAME> <CCC> <CCC_NAME>ip1</CCC_NAME> <TC> <TC_LOC>/tftpboot/tc1</TC_LOC> </TC> </CCC> <CCC_NAME>ip2</CCC_NAME> <TC> <TC_LOC>/tftpboot/tc1</TC_LOC> <TC_LOC>/tftpboot/tc3</TC_LOC> <TC_LOC>/tftpboot/tc4</TC_LOC> </TC> </CCC> </COMPONENT> <COMPONENT> <COMP_NAME>parser</COMP_NAME> <CCC> <CCC_NAME>p1</CCC_NAME> <TC> <TC_LOC>/tftpboot/tc1</TC_LOC> <TC_LOC>/tftpboot/tc2</TC_LOC> </TC> </CCC> <CCC_NAME>p2</CCC_NAME> <TC> <TC_LOC>/tftpboot/tc1</TC_LOC> </TC> </CCC> <CCC_NAME>p3</CCC_NAME> <TC> <TC_LOC>/tftpboot/tc1</TC_LOC> <TC_LOC>/tftpboot/tc2</TC_LOC> <TC_LOC>/tftpboot/tc3</TC_LOC> </TC> </CCC> </COMPONENT> </CCCMAP>
open (FILE, "< $mapfile") or die ("Unable to read the file $mapfile"); while (my $str = <FILE>) { chomp($str); $comp = $1 if $str =~ m{<COMP_NAME>(.*?)</COMP_NAME>}; $cmd = $1 if $str =~ m{<CCC_NAME>(.*?)</CCC_NAME>}; $tc = $1 if $str =~ m{<TC_LOC>(.*?)</TC_LOC>}; if ($tc) { push @tc, $tc; } if ( ($str =~ m{</TC>}) ) { $hoh{$comp}{$cmd} = {@tc}; #push @{$hoh{$comp}{$cmd}}, { @tc }; next; } elsif ( ($str =~ m{</CCC>})||($str =~ m{</COMPONENT>}) ) { undef @tc; undef $tc; next; } else { next; } } # print Dumper \%hoh;
there is minor error in my code which makes this hash improper$VAR1 = { 'ip' => { 'ip1' => { '/tftpboot/tc1' => '/tftpboot/tc1' }, ' +ip2' => { '/tftpboot/tc4' => '/tftpboot/tc4', '/tftpboot/tc1' => '/tf +tpboot/tc3' } }, 'parser' => { 'p2' => { '/tftpboot/tc1' => '/tftpboo +t/tc1' }, 'p3' => { '/tftpboot/tc3' => '/tftpboot/tc3', '/tftpboot/tc +1' => '/tftpboot/tc2' }, 'p1' => { '/tftpboot/tc2' => undef, '/tftpbo +ot/tc1' => '/tftpboot/tc2' } } };
$VAR1 = { 'ip' => { 'ip1' => { '/tftpboot/tc1' }, 'ip2' => { '/tftpboo +t/tc4', '/tftpboot/tc1', '/tftpboot/tc3' } }, 'parser' => { 'p2' => { + '/tftpboot/tc1' }, 'p3' => { '/tftpboot/tc3', '/tftpboot/tc1', '/tft +pboot/tc2' }, 'p1' => { '/tftpboot/tc1' => '/tftpboot/tc2' } } };
Edit: g0n - added readmore tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: error in my code
by davorg (Chancellor) on Nov 23, 2005 at 11:27 UTC | |
Re: error in my code
by reasonablekeith (Deacon) on Nov 23, 2005 at 11:52 UTC | |
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 | |
Re: error in my code
by Perl Mouse (Chaplain) on Nov 23, 2005 at 11:52 UTC |