in reply to 'my' buggy...

Okay, had a proper bit of playing with this and it's looking like the symbolic reference is getting the global value. As an example look at the code below.. uncomment as needed!

#!/usr/bin/perl $::test = 'Global'; test(); sub test { my $test = 'Local'; my $line = 'test'; # This returns 'Global'. # print ${$line}."\n"; # This returns 'local' # $line =~ s/\w+/${test}/gi; # This returns 'Global' # $line =~ s/(\w+)/${$1}/gi; print "$line..\n"; }

Does anyone know if this is a known thing with symbolic references? Does it effectively do a $::test?

Replies are listed 'Best First'.
Re: Re: 'my' buggy...
by Elian (Parson) on Apr 30, 2002 at 16:38 UTC
    Symbolic references only access globals. Nature of the beast. The only way to access lexicals by name at runtime, short of walking the pad, is with string eval, and that's not always 100% reliable.