02.09.2015, 10:46, "The Sidhekin" <[email protected]>:
>> So it seems that perl6 handles lexicals inside while (<>){} one-liners
>> differently.
>
> Ah, yes. Interesting. Run-time effect of C<my> not happening repeatedly.
> How would that deparse?
Good question, I wouldn't be surprised that -n switch has some kind of special
behavior.
> $ seq 3 | perl6 -e 'for lines() { my %d; %d{$_}++; END { say keys %d } }'
> 3
> $ seq 3 | perl6 -e 'for lines() { state %d; %d{$_}++; END { say keys %d } }'
> 1 2 3
> $
>
> … and while I'm comparing:
>
> $ seq 3 | perl6 -e 'for lines() { my %d; %d{$_}++; END { say keys %d } }'
> 3
> $ seq 3 | perl -E 'while (<>) { my %d; $d{$_}++; END { say keys %d } }'
> 1
>
> … I need me a new mental model. :-)
I think this is covered somewhere in RFC; perl6 repeatedly overwrites END{}
block where last one references last %d definition (say %d.WHICH).
perl5 on the other hand stays with first END{} block (say \%d).