Here is the output on data dumper:
$VAR1 = {'UserID' => ['1234'],
'MajorItems' =>
[{'MinorItem' => [{'Item'=>['Box']}]},
{'MinorItem' => [{'Item' =>['Suitcase']}]}]
};
My attempts to access the single item have still failed. :( | [reply] [d/l] |
My attempts to access the single item have still failed. :(
Fear not, my good monk, for perldsc, perlref, perlreftut are with you. Just drill down one level at a time.
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
my $xml = q{
<SuperItem>
<UserID>1234</UserID>
<MajorItems>
<MinorItem>
<Item>Box</Item>
</MinorItem>
</MajorItems>
<MajorItems>
<MinorItem>
<Item>Suitcase</Item>
</MinorItem>
</MajorItems>
</SuperItem>
};
my $struct = XMLin( $xml, ForceArray => 1 );
dumpit( $struct );
my $MajorItems_aref = $struct->{MajorItems};
dumpit( $MajorItems_aref );
my $SecondMinorItem_href = $struct->{MajorItems}[1];
# or $MajorItems_aref->[1]
dumpit( $SecondMinorItem_href );
my $MinorItem_aref = $struct->{MajorItems}[1]{MinorItem};
# or $SecondMinorItem_href->{MinorItem}
dumpit( $MinorItem_aref );
my $MinorItemFirst_href = $struct->{MajorItems}[1]{MinorItem}[0];
# or $MinorItem_aref->[0]
dumpit( $MinorItemFirst_href );
my $Item_aref = $struct->{MajorItems}[1]{MinorItem}[0]{Item};
# or $MinorItemFirst_href->{Item}
dumpit( $Item_aref );
my $luggage = $struct->{MajorItems}[1]{MinorItem}[0]{Item}[0];
# or $Item_aref->[0]
dumpit( $luggage );
sub dumpit
{
print Dumper( $_[0] );
}
| [reply] [d/l] |
My attempts have succeeded. My thanks to you!
| [reply] |