I am trying to write a Perl script that will traverse an XML file and find all entries named 'className'.
I am using a the XML::Simple library which is turning out to be very poorly named.
The library appears to represents sequences of similarly named elements as an array.
I am trying to iterate over the elements in the list, using a basic indexed loop. So I'm trying to find out how many elements are in the array:
} elsif("ARRAY" eq ref(@_[0])) {
my $list = @_[0];
print "scalar($list): " . scalar($list) . "\n";
print "\$#list: " . $#list . "\n";
print "\n";
}
Here is the output of my code:
scalar(ARRAY(0x600845398)): ARRAY(0x600845398)
$#list: -1
I've found references online to using the scalar function and the strange $#
notation, but neither is giving me a number that makes any sense.