However, Almost All questions about Perl syntax and things like this, even the confusing ones, can validly be answered with "RTFM." This doesn't mean that the answer in the manual is adequate to answer someone's question. It also implies that the asker knows where the manual is.
For example: if you were to tell a perl newbie with experience programming in C, "RTFM: It says right here, evaluate the array in a scalar context to get its length," that may be No Help At All, since context is a completely foreign concept to many C programmers.
I think a better attitude to take would be to reinterpret "How can I <basic syntax issue>" as "Where is the documentation for <basic syntax issue>?" If you teach the person where to find the answer, instead of telling them they shouldn't have asked the question, then maybe they will read the manual before posting in the future, now that they know where it is.
If you don't want to waste your time answering the question, don't do it. There are other monks less experienced than you who would be happy to help.
That said: there is a good answer to this question in the categorized Q&A section of Perl Monks as well: How do I find the size of an array?
As for array lengths: often you don't need them at all. If you're planning to loop over the elements of an array, often it's better practice to use a foreach style loop than a c-style loop:
Alanmy @array = qw(a few items in the array); foreach my $element (@array) { do_something_with($element); }
In reply to RE: Re: Finding the total number of elements in an array.
by ferrency
in thread Finding the total number of elements in an array.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |