I have simple XML that I want to read in Perl and make hash containing all read keys.
Consider this code:
my $content = $xml->XMLin("filesmap.xml")->{Item};
my %files = map { $_->{Path} => 1 } @$content;
This snippet works great when XML file contains many Item
tags. Then $content
is a reference to array. But when there is only one Item
I get an error when dereferencing as array. My assumption is that $content
is a reference to the scalar, not array.
What is the practice to make sure I get array of values read from XML?