Trey Harris trey-at-lopsa.org |Perl 6| wrote:

In 5.10, given seems to copy its argument, whereas for aliases it. (I haven't looked at the code; maybe it's COW-ing it.) If you add a C<say "Value is now $foo";> to the end of the below program, and then change C<for> to C<given> and run the program with values of $foo less than 500 or greater than 1000, you'll see the difference: with C<for>, the value remains changed after the block, with C<given> it is not.

I do not believe this distinction is true in Perl 6, is it?

Trey

Correct.  In S04,

"

If you rely on C<$_> as the implicit parameter to a block,
then C<$_> is considered read/write by default.  That is,
the construct:

   for @foo {...}

is actually short for:

   for @foo <-> $_ {...}

so you can modify the current list element in that case.

"



Are you saying that Perl 5.10 has given/when ? Or is that the CPAN module that basically rewrites the entire file?

--John

Reply via email to