I somewhat agree with you: I don't want PerlMonks to start being flooded with the same basic questions over and over.

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:

my @array = qw(a few items in the array); foreach my $element (@array) { do_something_with($element); }
Alan

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.