pez252 has asked for the wisdom of the Perl Monks concerning the following question:
<?xml version="1.0" encoding="utf-8"?> <get_devices_response> <devices list="true"> <device> <name>12345678</name> <id>1234</id> </device> <device> <name>87654321</name> <id>8765</id> </device> </devices> </get_devices_response>
$VAR1 = { 'devices' => { 'device' => [ { 'name' => '12345678', 'id' => '1234' }, { 'name' => '87654321', 'id' => '8765' } ], 'list' => 'true' } };
my $hash_ref = XMLin($XML, KeyAttr=>[] , ForceArray=>["device"]); print "The array\n"; print Dumper($hash_ref->{devices}->{device}); print "The first element\n"; print Dumper($hash_ref->{devices}->{device}[0]); print "The first element another way\n"; my @array=$hash_ref->{devices}->{device}; print Dumper($array[0]);
The array $VAR1 = [ { 'name' => '12345678', 'id' => '1234' }, { 'name' => '87654321', 'id' => '8765' } ]; The first element $VAR1 = { 'name' => '12345678', 'id' => '1234' }; The first element another way $VAR1 = [ { 'name' => '12345678', 'id' => '1234' }, { 'name' => '87654321', 'id' => '8765' } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pull an array from a hash... or somthing
by olus (Curate) on Feb 22, 2008 at 19:02 UTC | |
by pez252 (Novice) on Feb 22, 2008 at 19:29 UTC | |
|
Re: Pull an array from a hash... or somthing
by kyle (Abbot) on Feb 22, 2008 at 19:02 UTC | |
by pez252 (Novice) on Feb 22, 2008 at 19:44 UTC | |
|
Re: Pull an array from a hash... or somthing
by pez252 (Novice) on Feb 22, 2008 at 22:23 UTC |