Scarborough has asked for the wisdom of the Perl Monks concerning the following question:
Thank you for your consideration.use strict; use XML::Simple; use Data::Dumper; my ($user, $service) = ('Scarborough','dbjobs'); my $user_hash; #the real input comes from a file and is very much longer $user_hash = XMLin("<SERVICES> <SERVICE name='dbjobs'> <USER>Scarborough</USER> <USER>Whitby</USER> </SERVICE> <SERVICE name='reports'> <USER>Scarborough</USER> </SERVICE> </SERVICES>"); print Dumper($user_hash); #only here for testing if ($$user_hash{SERVICE}->{$service}){ print "$service exists\n"; #Here the problem begins #Why is @users getting a ref to the array my @users = @$user_hash{SERVICE}->{$service}->{USER}; print Dumper(@users); #have tried: foreach my $this_service (@$user_hash{SERVICE}->{ +$service}->{USER}) foreach my $this_user (@users){ print "\n".$this_user." ".$user."\n"; } } __END__ OUTPUT FROM PROGRAM $VAR1 = { 'SERVICE' => { 'dbjobs' => { 'USER' => [ 'Scarborough', 'Whitby' ] }, 'reports' => { 'USER' => 'Scarborough' } } }; dbjobs exists $VAR1 = [ 'Scarborough', 'Whitby' ]; ARRAY(0x1a79ea8) Scarborough
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Derefferencing the out put from XMLin()
by Plankton (Vicar) on Jun 08, 2004 at 16:14 UTC | |
|
Re: Derefferencing the out put from XMLin()
by antirice (Priest) on Jun 08, 2004 at 16:29 UTC |