Tom Browder <tom.brow...@gmail.com> writes:

> Perl 5 source
> ==========
>> my @aaa = qw( a b c d e f g );
>> for my $c (@aaa) {
>
> Perl::ToPerl6
> =========
>> my @aaa = qw ( a b c d e f g );
>> for (@aaa) -> $c {
>
> Blue_Tiger
> ========
>> my @aaa = < a b c d e f g >;
>> for @aaa <-> $c {
>
> For the example Perl 5 input I like the Blue_Tiger translation, except
> I haven't so far found an description of the '<->' operator.  Why
> would Blue_Tiger prefer it to the '->' operator which I've seen in all
> the examples I can remember seeing?

In Perl 5, the loop variable ($c) is an alias into the array, and changing its 
value changes the the value in the array.  In Perl 6, the array being worked on 
is read-only by default, so in the Perl::ToPerl6 example, trying to change the 
value of $c inside the loop would throw an error.  Using the <-> operator (also 
pointing back from the loop variable to the array) tells it to use the Perl 5 
behavior, where the array can be changed by changing the loop variable.


-- 
Aaron -- aaron.baugher.biz

Reply via email to