note
Don Coyote
<p>Point to note, the for loop uses the construct of <c>scalar(@arr)</c> and the map operation uses the special variable <c>$#</c> (+ arrayname) <c>$#arr</c> to determine the length of the list being implemented within the operations.</p>
<p>where <c>@arr = (1,2,3,4)</c></p>
<p><c>scalar(@arr)</c> returns the number of items in the list
<c>scalar(@arr) = 4</c></p>
<p><strike><c>$#arr</c> returns a zero indexed length of items list
<c>$#arr = 3</c>
</strike></p>
<p><c>$#arr</c> returns the highest index of the array
<c>$#arr = 3</c>
</p>
<p>The C style for loop has the condition of the increment being lower than <c>scalar(@arr)</c> where;</p>
<p><c>scalar(@arr) = 4, ( $i = 0, $i < scalar(@arr), $i++ ) = 0,1,2,3</c></p>
<p>The perl <c>map</c> operation however, inserts the incremented counter for the <c>$_</c> variable where;</p>
<p><c>$#arr = 3, 0..$#arr = 0,1,2,3</c></p>
<p><b>updates</b> to definition of <c>$#</c> variable as result of reply from Anomolous.</p>
<p>Should the <c>$ARRAY_BASE</c> special variable <c>$[</c> be set to other than the default of 0. The <c>$#arr</c> 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.</p>
<hr/>
<c>my @arr = split //,'Coyote'; print map {$arr[$_]} 0..$#arr;</c>
1001525
1001525