develooper Front page | perl.perl5.porters | Postings from April 2010

[perl #6870] Odd parsing of "do ... for ..."

Thread Previous
From:
Alexandr Ciornii via RT
Date:
April 30, 2010 01:44
Subject:
[perl #6870] Odd parsing of "do ... for ..."
Message ID:
rt-3.6.HEAD-27388-1272617030-560.6870-14-0@perl.org
Same result on 5.12.0.

On Sat Apr 21 23:30:11 2001, simon@netthink.co.uk wrote:

>  % ./perl -le '$a=do xa for ax;'
>  % ./perl -le 'do "xa" for ax;'
>  % ./perl -le 'do xa for ax;'
> Missing $ on loop variable at -e line 1.
>  % ./perl -le 'do xa for "ax"'
>  % ./perl -le 'do xa for sin(1)'
> Missing $ on loop variable at -e line 1.
>  % ./perl -le 'do xa for (sin(1))'
> 
> Get this:
>  % ./perl -le 'do xa for "sin"'
>  % ./perl -le 'do xa for qq(sin)'
> Missing $ on loop variable at -e line 1.
>  % ./perl -le 'do xa for my $a'
>  % ./perl -le 'do xa for my @a'
> Missing $ on loop variable at -e line 1.
> 
> The "Missing $" only happens for package/do/require/use followed by
> bareword, and no other builtins, and where 'for' is followed by
> anything other than /[$%@("']/ or my/our $foo.
> 
> I can't see how it's getting that, because allowing "my" and "our"
>    with
> a scalar suggests it's parsing "for" as the beginning of a statement,
> but "for @a" is not allowed at the beginning of a statement, and
>    Deparse
> reports:
>      % ./perl -Ilib -MO=Deparse -le 'do xa for my $a'
> 
>     foreach $_ (my($a)) {
>         do 'xa';
>     }

-- 
Alexandr Ciornii, http://chorny.net


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About