Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: using strict refs

by bwana147 (Pilgrim)
on Aug 28, 2001 at 17:54 UTC ( [id://108440]=note: print w/replies, xml ) Need Help??


in reply to using strict refs

Locally disable the strict (UPDATE: NO, DON'T! Praises go to Hofmator for correcting this goof):

#!/usr/bin/perl -w use strict; my $i = "test"; my $test = "success"; { no strict 'refs'; print "$$i\n"; }
Or use eval:
#!/usr/bin/perl -w use strict; my $i = "test"; my $test = "success"; print eval qq{"\$$i\\n"};

--bwana147

Replies are listed 'Best First'.
Re: Re: using strict refs
by Hofmator (Curate) on Aug 28, 2001 at 18:02 UTC

    The eval version works, the other version doesn't work because symbolic references only work for package variables - not for lexical variables declared with my. So:

    #!/usr/bin/perl -w use strict; my $i = "test"; # this is now a package variable and requrires an explicit # package name because of use strict $main::test = "success"; { no strict 'refs'; print "$$i\n"; }

    -- Hofmator

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://108440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found