Greg London <[EMAIL PROTECTED]> said something to this effect on 10/18/2001:
> 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.
If ($$ref eq $var) then this is probably just Perl reuing the SV.
> 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.
You are holding on to the reference to $var, so Perl can't reuse
that SV.
> 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.
This doesn't sound feasable to me. If this was the case, then
you would think that, on a busy machine, a larger number of
iterations would eventually give different results for $ref. In
my tests (perl 5.6.1) any number of iterations (where "any
number" is defined as 5, 25, 50, and 100) gave the same
address.
> well, that, or maybe the optimizer can somehow detect
> that I throw the vars away in the first script,
> and therefore reuses the address.
This is what I'm thinking.
(darren)
--
He who has never configured `sendmail.cf' has no courage.
He who has configured it more than once has no brain.