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

There's surely somebody out there, who wrote the code, and could explain it better... ;-)

Aliasing means, that the carcass of the variable is retained (its content saved to be restored later) and filled with a new structure, i.e. it gets a new pointer. Let's have a look. Loop with a symbol table variable:

perl -MDevel::Peek -le 'our $f = 42; Dump *f{SCALAR}; for $f (2) { Dum +p *f{SCALAR} }' SV = RV(0x8664670) at 0x863bc28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x863c7bc SV = IV(0x8657eec) at 0x863c7bc REFCNT = 2 FLAGS = (IOK,pIOK) IV = 42 SV = RV(0x8664670) at 0x863be2c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x863c7ec SV = IV(0x8657ee8) at 0x863c7ec REFCNT = 3 FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK) IV = 2

Note that the scalar variable (SV) contains the same reference value (RV(0x8664670)) outside and inside the loop. It's content however is allocated at a different memory location:

SV = RV(0x8664670) at 0x863bc28 # outside SV = RV(0x8664670) at 0x863be2c # inside

That's essentially the same for my variables.

perl -MDevel::Peek -le 'my $f = 42; Dump \$f; for $f (2) { Dump \$f } +for my $f (2) { Dump \$f }' SV = RV(0x9d1a678) at 0x9cf1c28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9cf1cdc SV = IV(0x9d0def8) at 0x9cf1cdc REFCNT = 2 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 42 SV = RV(0x9d1a678) at 0x9cf1e2c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9cf1c28 SV = IV(0x9d0defc) at 0x9cf1c28 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 2 SV = RV(0x9d1a678) at 0x9cf1c28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9cf1e2c SV = IV(0x9d0defc) at 0x9cf1e2c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 2

Here we have three different storage locations, because the two loops have each its own scope:

SV = RV(0x9d1a678) at 0x9cf1c28 SV = RV(0x9d1a678) at 0x9cf1e2c SV = RV(0x9d1a678) at 0x9cf1c28

The RV(0x9d1a678) is the same, which shows us that the following for loops are aliasing the same $f :

my $f; for $f (1..3) { } for my $f (1..3) { }

In the perl sources, you'll find the relevant code which sets up the loop variable at Perl_newFOROP() in file op.c, and the "aliasing code" in pp_ctl.c at PP(pp_enteriter).

update: corrected code locations