hey all,
when I run this script:
for (my $cnt=0; $cnt<5; $cnt++)
{
my $var = 'hello';
my $ref = \$var;
print "ref is $ref \n";
}
it turns out that ref is pointing to
the exact same address every time
through the loop.
when I modify the script like this:
my @arr;
for (my $cnt=0; $cnt<5; $cnt++)
{
my $var = 'hello';
my $ref = \$var;
push(@arr, $ref);
print "ref is $ref \n";
}
I get what I originally expected,
namely, each "my"ed variable is at a different
address.
in the first script, was perl "my"ing a
variable everytime through the loop,
but it just happened to be at the same address?
i.e. "my" a var, then garbage collect, and
the next "my" var ends up using the spot just
freed up.
it's the only explanation I can think of.
well, that, or maybe the optimizer can somehow detect
that I throw the vars away in the first script,
and therefore reuses the address.
I'm running perl 5.6.0
Greg