That's a feature of XML::Simple - this difference of behavior between a node which happens once or multiple times. Most of the time, when you expect a node that happen one or more times, you want to tell XML::Simple to always return an array of hashes, so you have a uniform way to deal with the data.
That's what ForceArray attribute for.
will guarantee that every time Layer is seen, it creates an array (ref).$data = XMLin( $xml, ForceArray => [ qw(Layer) ] )
Otherwise you'll always have to code something like that:
my $layers = $data->{Capabilities}->{Layer}; for my $layer ( ref $layers eq 'ARRAY' ? @$layers : ( $layers ) ) { # do something to each Layer }
In reply to Re: Checking if a variable is an array
by ferreira
in thread Checking if a variable is an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |