Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Symbolic Reference not Dereferencing

by spacewarp (Pilgrim)
on Jun 03, 2002 at 18:56 UTC ( #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.

Comment on Symbolic Reference not Dereferencing
Select or Download Code
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';

      What is our? I can't find it in the index of the camel book.
      Spacewarp

      DISCLAIMER:
      Use of this advanced computing technology does not imply an endorsement
      of Western industrial civilization.
        our. There is so many ways to find documentation or information: Unix manual, info file, perldoc.com, google. Please learn to use them.

        -- stefp -- check out TeXmacs wiki

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?
(jeffa) Re: Symbolic Reference not Dereferencing
by jeffa (Chancellor) 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

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-12-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls