[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: Localization method of $1
On Sun, Jan 16, 2000 at 12:20:25PM -0800, Peter Scott wrote:
[Back to p5p.]
> $x = "foo";
> print "Initial: ", pref $x;
> {
> local $x = "bar";
> print "In block: ", pref $x;
> }
> print "After block: ", pref $x;
>
> Initial: SCALAR(0x80f8db8) = foo
> In block: SCALAR(0x80eb66c) = bar
> After block: SCALAR(0x80f8db8) = foo
>
> The 'local $x' has a new address; I can still get at the original $x inside
> the block if I make a reference to it first.
This is an implementation detail - which in principle might be
considered to be a bug any time.
> But that's not what's happening with $1:
Correct. Saving value of $1 is done via a different mechanism. $1 is
kinda-tied, and localization is done by kinda-changing-the-FETCH-data:
{ package backref1; our $dollar1 = \undef; sub FETCH { $$dollar1 } }
Localization is done by kinda-doing
local $dollar1 = \$$dollar1;
on the entry into a block (only this \$$dollar1 is kinda-precomputed
at compile time, thus there is no runtime penalty).
The real implementation is not via tie(), but via a different type of
magic. And access is not via $$dollar1, but via calculations over
non-SV storage, so it cannot be completely expressed via Perl syntax.
But I hope you got the feeling...
Ilya
- Follow-Ups from:
-
Peter Scott <Peter@PSDT.com>
- References to:
-
Peter Scott <Peter@PSDT.com>
Ilya Zakharevich <ilya@math.ohio-state.edu>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]