no strict 'refs';
foreach my $F (@$Fields) {*{$F} = \ $_t->{$F}->[$_r]};
####
use strict;
use warnings;
use Devel::Peek;
our ($a, $b, $c);
my @fields = qw(a b);
print "\nBefore setting a value for \$a:\n";
Dump($a);
$a = 'Test';
$b = 'Unused';
print "\nAfter setting a value for \$a:\n";
Dump($a);
$c = 'Clobbered';
print "\nAnd \$c is:\n";
Dump($c);
print "\nGlobref \*a is:\n";
Dump(*a);
{
no strict 'refs';
my %tmp;
$tmp{$_} = \${$_} for(@fields);
print "\nAfter saving references \\\%tmp is:\n";
Dump(\%tmp);
*{'a'} = \$c;
print "\nAfter aliasing \$a to \$c, \$a is:\n";
Dump($a);
print "\nAfter aliasing \$a to \$c, \*a is:\n";
Dump(*a);
*{$_} = $tmp{$_} for(@fields);
print "\nAfter restoring \*a, \*a is:\n";
Dump(*a);
}
print "\nFinally, \$a is:\n";
Dump($a);
####
Before setting a value for $a:
SV = NULL(0x0) at 0x8ecfa60
REFCNT = 1
FLAGS = ()
After setting a value for $a:
SV = PV(0x8ebe0c0) at 0x8ecfa60
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8ed8618 "Test"\0
CUR = 4
LEN = 8
And $c is:
SV = PV(0x8ebe0d0) at 0x8edf228
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8ed4b88 "Clobbered"\0
CUR = 9
LEN = 12
Globref *a is:
SV = PVGV(0x8ef2840) at 0x8ecfa50
REFCNT = 10
FLAGS = (MULTI)
NAME = "a"
NAMELEN = 1
GvSTASH = 0x8ec0048 "main"
GP = 0x8ed8c28
SV = 0x8ecfa60
REFCNT = 1
IO = 0x0
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x0
CVGEN = 0x0
LINE = 8
FILE = "./test.pl"
FLAGS = 0x2
EGV = 0x8ecfa50 "a"
After saving references \%tmp is:
SV = IV(0x8ec0e14) at 0x8ec0e18
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x8f01bf8
SV = PVHV(0x8ec5454) at 0x8f01bf8
REFCNT = 2
FLAGS = (PADMY,SHAREKEYS)
ARRAY = 0x8ecf330 (0:6, 1:2)
hash quality = 125.0%
KEYS = 2
FILL = 2
MAX = 7
RITER = -1
EITER = 0x0
Elt "a" HASH = 0xca2e9442
SV = IV(0x8ec0e24) at 0x8ec0e28
REFCNT = 1
FLAGS = (ROK)
RV = 0x8ecfa60
SV = PV(0x8ebe0c0) at 0x8ecfa60
REFCNT = 2
FLAGS = (POK,pPOK)
PV = 0x8ed8618 "Test"\0
CUR = 4
LEN = 8
Elt "b" HASH = 0xdb819b
SV = IV(0x8ec0e44) at 0x8ec0e48
REFCNT = 1
FLAGS = (ROK)
RV = 0x8ecfa90
SV = PV(0x8ebe0c8) at 0x8ecfa90
REFCNT = 2
FLAGS = (POK,pPOK)
PV = 0x8ee98b8 "Unused"\0
CUR = 6
LEN = 8
After aliasing $a to $c, $a is:
SV = PV(0x8ebe0d0) at 0x8edf228
REFCNT = 2
FLAGS = (POK,pPOK)
PV = 0x8ed4b88 "Clobbered"\0
CUR = 9
LEN = 12
After aliasing $a to $c, *a is:
SV = PVGV(0x8ef2840) at 0x8ecfa50
REFCNT = 10
FLAGS = (MULTI)
NAME = "a"
NAMELEN = 1
GvSTASH = 0x8ec0048 "main"
GP = 0x8ed8c28
SV = 0x8edf228
REFCNT = 1
IO = 0x0
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x0
CVGEN = 0x0
LINE = 8
FILE = "./test.pl"
FLAGS = 0x2
EGV = 0x8ecfa50 "a"
After restoring *a, *a is:
SV = PVGV(0x8ef2840) at 0x8ecfa50
REFCNT = 10
FLAGS = (MULTI)
NAME = "a"
NAMELEN = 1
GvSTASH = 0x8ec0048 "main"
GP = 0x8ed8c28
SV = 0x8ecfa60
REFCNT = 1
IO = 0x0
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x0
CVGEN = 0x0
LINE = 8
FILE = "./test.pl"
FLAGS = 0x2
EGV = 0x8ecfa50 "a"
Finally, $a is:
SV = PV(0x8ebe0c0) at 0x8ecfa60
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8ed8618 "Test"\0
CUR = 4
LEN = 8