On 7/31/07, Rodrigo Tavares <[EMAIL PROTECTED]> wrote:
> Hello John,
>
> You could explain the below line ?
>
>  print join( ',', ( $arrow[ $_ ] ) x ( $_ + 1 ) ),
> "\n";
snip

x is the repetition operator.

When the left side is a scalar it builds a string that contains the
left side repeated the right side times: "a" x 5 == "aaaaa".   When
the left side is a list it creates a list with each element repeated
the right side times (in the original order): (1, 2, 3) x 3 == (1, 2,
3, 1, 2, 3, 1, 2, 3).  So in the example above $_ is the offset into
the array.  For the first element it is 0 so we have

print join(",", ($arrow[0]) x 1), "\n";

which is the same as

print join(",", $arrow[0]), "\n";

for the second element $_ is 1 so we have

print join(",", ($arrow[1]) x 2), "\n";

which is the same as

print join(",", $arrow[1], $arrow[1]), "\n";

for the third element $_ is 2 so we have

print join(",", ($arrow[2]) x 3), "\n";

which is the same as

print join(",", $arrow[2], $arrow[2], $arrow[2]), "\n";

and so on.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to