Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Symbolic Reference not Dereferencing

by spacewarp (Pilgrim)
on Jun 03, 2002 at 18:56 UTC ( [id://171305]=perlquestion: print w/replies, xml ) Need Help??

spacewarp has asked for the wisdom of the Perl Monks concerning the following question:

I have a strange problem.. I'm trying to use a symbolic reference to refer to a variable's data, but it just isn't working. Everything I've done appears to be straight out of Advanced Perl Programming, Chapter 1, but this:
#!/usr/bin/perl -w use strict; no strict 'refs'; my $A; my $var; $A = "YES"; $var = "A"; print "$A\n"; print "$var\n"; print "$$var\n";
Only produces this:
YES A Use of uninitialized value at ./work2.pl line 13.
Any help would be appreciated, as my deadline looms and my boss fumes. 8)
Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.

Replies are listed 'Best First'.
Re: Symbolic Reference not Dereferencing
by danger (Priest) on Jun 03, 2002 at 19:02 UTC

    You can only symbolically reference package global variables, not lexical variables. Try it with our $A; or use vars '$A';

    A reply falls below the community's threshold of quality. You may see it by logging in.
(jeffa) Re: Symbolic Reference not Dereferencing
by jeffa (Bishop) on Jun 03, 2002 at 19:09 UTC
    danger is correct - i just wanted to add that you can usually get safer results by using your own hash instead of the package's:
    use strict; my %var = ( A => 'YES', ); print $var{A}, "\n";

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Symbolic Reference not Dereferencing
by stefp (Vicar) on Jun 03, 2002 at 19:12 UTC
Re: Symbolic Reference not Dereferencing
by Anonymous Monk on Jun 03, 2002 at 19:04 UTC
    DISCLAIMER: Use of this advanced computing technology does not imply an endorsement of Western industrial civilization.
    I assume you are an Elbonian programmer?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found