develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991114.001] dangerous behavior from local

From:
Tom Christiansen
Date:
November 16, 1999 06:17
Subject:
Re: [ID 19991114.001] dangerous behavior from local
Message ID:
199911161416.HAA06733@jhereg.perl.com
Watch this:

    Top                  x= 0 y=stone  &x=080da578 &y=080da59c
    Inside Before        x=10 y=fred   &x=080d3f8c &y=080d3e9c
    Inside               x=20 y=barney &x=080da548 &y=080d3e9c
    Outside              x=10 y=barney &x=080d3f8c &y=080d3e9c
    Way Outside          x= 0 y=stone  &x=080da578 &y=080da59c

That's produced by the attached program.  Notice that the 
address of y is not altered inside, whereas that of x is.

--tom

$x = '0';
$y = "stone";

sub show {
    printf "%-20s x=%2d y=%-6s &x=%08x &y=%08x\n",
	shift, $x, $y, \$x, \$y;
} 

show("Top");

{
    local $x = 10;
    local $y = "fred";

    show("Inside Before");

    {
	local $x = 20;
	local($y = "barney");
	show("Inside");
    } 
    show("Outside");
}

show("Way Outside");



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