Number of Items in Array



In the Perl documentation (perlintro) it says that you can find out the number
of elements in an array using the following syntax:

print $myvar[$#mmyvar];

I am running into a problem when I try to find the number of elements in an
array that is being returned from an object.

I am using XML::Simple to parse an XML document, and have the following
snippet of code giving me trouble:

print $#xml->{'channel'};
for ($i=0; $i <= $#xml->{'channel'}; $i++) {
print $xml->{'channel'}[$i];
}

It bombs on the very first line of the snippet with an error "Use of
unitialized value in print..."

If I take the '#' out and just run:
print $xml->{'channel'};

I get "ARRAY(0x84711a4)" as output.

This would lead me to believe that I am indeed passing an initialized array to
the print function...?

I have been diging through the documentation and various websites for
literally 6 hours now. I'm beginning to suspect I may be missing something
extremely obvious (making myself look like an idiot) or that maybe it has
something to do with the way Perl handles references...?

Does anyone have any suggestions or pointers?

Thanks for your time.

--
Aaron C. de Bruyn
aaron@xxxxxxxxxxxxx

.-.
/v\ L I N U X
// \\ >Penguin Power<
/( )\
^^-^^
.



Relevant Pages

  • Re: Vectorizing assignment to a structure arrays array field
    ... You first algo and your second algo and us's algo do give ... The us algorithm did reveal that arrayfun can operate on ... also contrary to the documentation. ... comparing fields of elements of a struct array. ...
    (comp.soft-sys.matlab)
  • Re: [PHP] Object to array conversion oddity
    ... casting from object to array indicates ... that you no longer want the constraints of property protection, ... behave the way the documentation pointed it out, ... or the behavior needs to be modified. ...
    (php.general)
  • Re: [PHP] Object to array conversion oddity
    ... casting from object to array indicates ... Blah, blah, blah. ... The documentation is probably out of date and applied ... scalable system for accessing system services | ...
    (php.general)
  • Re: windows 95 RPC
    ... After the original Windows 95, RPC in following Win9x family is ... no /robust support is available in Win9x and NT4 family though. ... We might need to follow up with documentation. ... In your definition, ptr becomes a multi-dimensional array, whose first ...
    (microsoft.public.win32.programmer.networks)
  • Re: why the perl documents is hard to understand?
    ... I was taught that there is a trick to learn unix/linux. ... reading the online documentation. ... "I find Perl documentation hard to read". ... WHAT is confusing, and WHY it is difficult to understand. ...
    (comp.lang.perl.misc)