in reply to can't use string as a SCALAR ref while strict refs
use strict; my $b = '1'; my $a = \$b; $$a = '2'; print $b;You must declare $b before referencing it as \$b (I know, I have tested my code), because typing
my $a = \$b; my $b = '1';in this order will autovivify a variable $main::b and then declare a different $b "my" variable.
The reason why your program prints '1' is nearly the same. You can use symbolic references (opr string references as you call it), only to package variables. You cannot use a symbolic reference to a "my" variable. So, in your code, you have two variables:
my $b $main::bThat's all !
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: can't use string as a SCALAR ref while strict refs
by dws (Chancellor) on Feb 28, 2002 at 07:00 UTC | |
by jsegal (Friar) on Feb 28, 2002 at 19:29 UTC |