in reply to Re: can't use string as a SCALAR ref while strict refs
in thread can't use string as a SCALAR ref while strict refs

Another way to look at this is to ponder
{ my $b = '1'; my $a = 'b'; $$a = 2; print "b = $b\n"; } print "b = $b\n";
and consider which $b is getting set, and why. This might require a detour into the documentation on what, exactly, 'my' does.

Replies are listed 'Best First'.
Re: Re: Re: can't use string as a SCALAR ref while strict refs
by jsegal (Friar) on Feb 28, 2002 at 19:29 UTC
    Symbolic references, which the initial question is about, require entries in the symbol table. "my" does not place entries in the symbol table. This explains the behavior the initial poster asked about, and also answers why you will get
    b = 1 b = 2
    for your output. The setting of $$a to 2 sets the global $b to 2, but inside the block $b refers to the lexical $b with no symbol table entry.
    Hope this helps...
    Other posters have mentioned that what the original poster may really want to use are the hard references...

    -JAS