Number of Items in Array
- From: aaron@xxxxxxxxxxxxx (Aaron C. de Bruyn)
- Date: Mon, 18 Apr 2005 00:18:59 -0700
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<
/( )\
^^-^^
.
- Follow-Ups:
- RE: Number of Items in Array
- From: Charles K. Clarkson
- RE: Number of Items in Array
- Prev by Date: Re: passing database data to a sub
- Next by Date: utf8 questions.
- Previous by thread: last question on the switch statement ....
- Next by thread: RE: Number of Items in Array
- Index(es):
Relevant Pages
|