in reply to Re^6: Hard syntax error or disambiguable parsing?
in thread Hard syntax error or disambiguable parsing?

I think the way it came about it that the foreach version of for each requires that the loop variable be aliased to the items in the list, and (at least historically) Perl's aliasing is achieved through globs.

So, pre-lexicals, the localisation was done by doing local *loopvar; under the covers.

Once lexicals came to pass, the quick fix for dealing with aliasing a lexical was to do the (rough?) equivalent of:

$_ = 'fred'; my $i = 123; { local *_ = \$i; for $i ( 1 .. 5 ) { print $i; } } print "\$_:$_ \$i:$i" 1 2 3 4 5 $_:fred $i:123

Which use *_ as the glob (per an implicit loop var loop), but allows the programmer to refer to the temporary variable by name within the loop body, whilst ensuring that both *_ and $i get restored afterward.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^8: Hard syntax error or disambiguable parsing?
by rovf (Priest) on Jan 30, 2009 at 08:52 UTC
    So, pre-lexicals, the localisation was done by doing local *loopvar; under the covers.

    Since *loopvar is localised, not $loopvar, does this mean that in

    our @loopvar; foreach $loopvar (...) { ... }
    I can not access the outer @loopvar, because it is masked then too?

    -- 
    Ronald Fischer <ynnor@mm.st>

      My knowledge of Perl doesn't go back to pre-lexical days, so I don't know for sure, but I doubt it. Maybe that should be local $loopvar;?

      As I thought I made clear, I'm just trying to interpret what I see in code and comments to piece together a possible scenario for how the current situation came about. Ie. It's all supposition and sourcecode forensics founded upon my inability to see any reasoning by which it would have been explicitely architected to operate this way.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I can not access the outer @loopvar, because it is masked then too?

      Try it ;-) But no, the @loopvar isn't masked, only the SCALAR slot in the typeglob gets a new reference.