> On 02 Sep 2015, at 14:02, Matija Papec <mpapec2...@yandex.com> wrote:
> 02.09.2015, 10:46, "The Sidhekin" <sidhe...@gmail.com>:
>>>  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).

A much shorter way, using Perl 6 features:

  $ seq 3 | perl6 -e ‘lines.Set.keys.say’

lines() reads lazily from STDIN and chomps them
Set is a coercer that turns the input into a Set
then take the keys of the set and show them






Liz

Reply via email to