develooper Front page | perl.perl5.porters | Postings from March 2003

Re: [perl #21404] local breaks aliasing

Thread Previous
From:
hv
Date:
March 1, 2003 10:15
Subject:
Re: [perl #21404] local breaks aliasing
Message ID:
200303011817.h21IHsP03824@crypt.compulink.co.uk
Michael G Schwern (via RT) <perlbug-followup@perl.org> wrote:
:#!/usr/bin/perl -wl
:
:$foo = 42;
:*bar = \$foo;
:
:print "$bar $foo ". \$bar . ' '. \$foo;
:
:{ local $bar = 23;  print "$bar $foo ". \$bar . ' '. \$foo }
:{ local $foo = 23;  print "$bar $foo ". \$bar . ' '. \$foo }
:
:$ perl5.8.0 ~/tmp/bug.plx
:42 42 SCALAR(0x569dc) SCALAR(0x569dc)
:23 42 SCALAR(0x4c59c) SCALAR(0x569dc)
:42 23 SCALAR(0x569dc) SCALAR(0x56a00)
:
:I expected something like
:
:42 42 SCALAR(0x569dc) SCALAR(0x569dc)
:23 23 SCALAR(0x4c59c) SCALAR(0x4c59c)
:23 23 SCALAR(0x56a00) SCALAR(0x56a00)
:
:If you change "*bar = \$foo" to "*bar = *foo" it works.
:
:Problem appears to be in all modern versions of Perl.
:
:Bug or feature?

I'd say feature: C< *bar = \$foo; > changes the SV slot of *bar
to be the same address as $foo; C< local $bar > changes the SV
slot of *bar to be a new value. C< *bar = *foo > changes the GP of
*bar to be that same as that of *foo.

I don't think there is a way of getting the effects you want without
aliasing the entire glob, unless you're suggesting changing perl to
add an extra level of indirection (which I don't think there is a
case for).

Hugo

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About