my @inputArray = (1,2,3,4,5,6,7,8);
my $inputArrayLen = @inputArray;

Even given the recursive context in which the OPed question is couched, I'm a bit surprised that no one has yet mentioned the  $# array operator (if that's the correct terminology), which gives you the maximum index of the array. (Update: See perldata for a discussion of  $# and arrays.)

As others have pointed out, evaluating an array in scalar context as in the
    my $inputArrayLen = @inputArray;
statement yields the number of elements of the array. Using the  $# operator, the statement
    my $maxIndex = $#inputArray;
gives you the highest index of any element in the array.
Leaving aside any considerations of recursion, the idiomatic, "Perlish" way of iterating over an array is something like
    my @array = (...);
    ...
    for my $element (0 .. $#array) {
        do_something_with($element);
        }
Leaving aside any considerations of recursion, a better way of iterating over an array is something like
    my @array = (...);
    ...
    for my $i (0 .. $#array) {
        do_something_with($array[$i]);
        }
and better yet IMHO, the idiomatic, "Perlish" way would be
    for my $element (@array) {
        do_something_with($element);
        }

Of course, there are other ways, such as using the built-in functions map and grep, of iterating over arrays, but those are other stories for other days.

Update: Fixed the brainfart for-loop example.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Use of uninitialized value in print at line 20 (#1) by AnomalousMonk
in thread Use of uninitialized value in print at line 20 (#1) by dishantarora

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.