01.09.2015, 19:46, "The Sidhekin" <sidhe...@gmail.com>:
>>  perl6 -ne 'my %d; %d{ .words[1] }++; END { %d.sort.perl.say }'
>>
>>  as this could not work in perl5
>>
>>  perl -nE 'my $d =1; END { say $d//"default!" }' # gives default
>
>    It's not the scoping.  It's scoped correctly, it's just that you need to 
> give it something to read, for the code to run, and the assignment to happen:
>
>  $ echo | perl -nE 'my $d =1; END { say $d//"default!" }'
>  1


I've picked a wrong example,

seq 3 | perl -nE 'my %d; $d{$_}++; END { say keys %d }'

vs

seq 3 | perl6 -ne 'my %d; %d{$_}++;  END { say keys %d }'

So it seems that perl6 handles lexicals inside while (<>){} one-liners 
differently.


>    Aside – hey, this is a Perl6 list, right? – you may find the following 
> difference … illuminating. :)
>
>  $ </dev/null | perl6 -ne 'my $d is default(1); END { say $d//"default!" }'
>  1
>  $ </dev/null | perl6 -ne 'my $d =1; END { say $d//"default!" }'
>  default!

Well, I have no idea what the rules for scoping are; I'm still missing 
B::Deparse. :)


Reply via email to