in reply to list assignment and undef
I left one of your questions unanswered: Why do the values returned by 1..10 appear to be global?
$ perl -MDevel::Peek -e'Dump $_ for 1' SV = IV(0x816a408) at 0x814f6f0 REFCNT = 2 FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK) IV = 1 $ perl -MDevel::Peek -e'Dump $_ for 1..1' SV = IV(0x816a40c) at 0x814ed9c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1
I've touched on it before. Range operators in list context with constants for arguments are expanded once (at compile-time?) and cached.
I wish I could explain the following:
$ perl -le'for (1..2) { map { print($_++) } 1..2 }' 1 2 2 3 $ perl -le'for (1..2) { for (1..2) { print($_++) } }' 1 2 1 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: list assignment and undef (range returns non-temps)
by Marshall (Canon) on Aug 26, 2009 at 14:44 UTC | |
by ikegami (Patriarch) on Aug 26, 2009 at 16:54 UTC | |
by Marshall (Canon) on Aug 26, 2009 at 19:58 UTC |