in reply to lexicals are all the same scalar and never go out of scope?
Try this:
use Devel::Peek; ... sub save { Dump $_[0]; push(@savearr, \$_[0]); readonly_on(${$savearr[-1]}); Dump ${$savearr[-1]}; } ... __END__ SV = PV(0x75cbc8) at 0x88d238 # REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x77e340 "begin 0 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cc68) at 0x75ef48 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x77e940 "begin 0 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cbc8) at 0x88d238 # REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x77e340 "begin 1 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cce8) at 0x7836b8 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x78cc60 "begin 1 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cbc8) at 0x88d238 # REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x77e340 "begin 2 end"\0 CUR = 11 LEN = 16 SV = PV(0x75ccf8) at 0x783700 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x87bb70 "begin 2 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cbc8) at 0x88d238 # REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x77e340 "begin 3 end"\0 CUR = 11 LEN = 16 SV = PV(0x75cd08) at 0x783748 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x87bcd0 "begin 3 end"\0 CUR = 11 LEN = 16 $VAR1 = [ \'begin 0 end', \'begin 1 end', \'begin 2 end', \'begin 3 end' ];
Note that the marked instances are in fact the same scalar. A new one isn't created before pushing it onto the array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: lexicals are all the same scalar and never go out of scope?
by ikegami (Patriarch) on Dec 06, 2011 at 09:55 UTC | |
by Eliya (Vicar) on Dec 06, 2011 at 10:32 UTC | |
by ikegami (Patriarch) on Dec 06, 2011 at 10:44 UTC | |
|
Re^2: lexicals are all the same scalar and never go out of scope?
by patcat88 (Deacon) on Dec 06, 2011 at 10:02 UTC | |
by ikegami (Patriarch) on Dec 06, 2011 at 10:43 UTC |