$\ = "\n"; # automatically add newlines to output $Foo = 4; # create the var print '*Foo{SCALAR} = ', *Foo{SCALAR}; # print the glob entry my $x = \$Foo; # make a reference... which is print '$x = ', $x; # the same as the glob entry.. duh $$x = 5; # change via reference print '$Foo = ', $Foo; # var has changed my $y; print "Enter scope"; { local $Foo = 42; # let the magic begin! print '*Foo{SCALAR} = ', *Foo{SCALAR}; # it's different! $y = \$Foo; # take a ref to this new thing print '$y = ', $y; # the same as the *new* glob entry print '$Foo = ', $Foo; # foo is 42 print '$$x = ', $$x; # print old var via reference.. unchanged print '$$y = ', $$y; # print new var via reference.. it's 42 $$x = 6; # change via reference to *old* print '$Foo = ', $Foo; # nothing happened to the local one! # but wait... } print "Exit scope"; print '*Foo{SCALAR} = ', *Foo{SCALAR}; # old glob entry is back print '$Foo = ', $Foo; # and we changed this one via $x earlier! print '$y = ', $y; # now the last remaining reference to local var print '$$y = ', $$y; # still 42 #### *Foo{SCALAR} = SCALAR(0x511f4) # original entry in glob $x = SCALAR(0x511f4) # ref to original scalar (same) $Foo = 5 # original value Enter scope *Foo{SCALAR} = SCALAR(0x47650) # new SCALAR entry in glob $y = SCALAR(0x47650) # ref to it $Foo = 42 # value of localized var $$x = 5 # value of original $$y = 42 # value via ref to localized var $Foo = 42 # after editing original, local unchanged Exit scope *Foo{SCALAR} = SCALAR(0x511f4) # original entry back in glob $Foo = 6 # change we made via $$x now visible $y = SCALAR(0x47650) # the localized var still around via ref $$y = 42 # still contains value