Point to note, the for loop uses the construct of scalar(@arr) and the map operation uses the special variable $# (+ arrayname) $#arr to determine the length of the list being implemented within the operations.

where @arr = (1,2,3,4)

scalar(@arr) returns the number of items in the list scalar(@arr) = 4

$#arr returns a zero indexed length of items list $#arr = 3

$#arr returns the highest index of the array $#arr = 3

The C style for loop has the condition of the increment being lower than scalar(@arr) where;

scalar(@arr) = 4, ( $i = 0, $i < scalar(@arr), $i++ ) = 0,1,2,3

The perl map operation however, inserts the incremented counter for the $_ variable where;

$#arr = 3, 0..$#arr = 0,1,2,3

updates to definition of $# variable as result of reply from Anomolous.

Should the $ARRAY_BASE special variable $[ be set to other than the default of 0. The $#arr may return an offset to the zero indexed result that you are probably not expecting. Generally use of this variable is frowned upon at best. However.. dah dih dah dih.


my @arr = split //,'Coyote'; print map {$arr[$_]} 0..$#arr;

In reply to Re: @array elements multiplication with another array elements. by Don Coyote
in thread @array elements multiplication with another array elements. by New Perlmonk

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.