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

RE: Re: question about variabies/references (ignore my previous botched entry)

by btrott (Parson)
on Apr 05, 2000 at 20:12 UTC ( [id://6947]=note: print w/replies, xml ) Need Help??


in reply to Re: question about variabies/references (ignore my previous botched entry)
in thread question about variabies/references (ignore my previous botched entry)

You (chromatic) wrote:
> Another piece of the puzzle is that putting curly > braces around anything that looks like a variable > causes Perl to interpolate the value of that > variable. Doing: > > $main::{$test} = "skot2"; > > first causes interpolation -- so that the > interpreter now has: > > $main::scott = "skot2";
No, I don't think this is true. When you do
$main::{$test} = "skot2";
you're manipulating the symbol table of package main; this is a very different thing than modifying a scalar variable ($main::scott). $main::scott and $main::{"scott"} are two different things.

Replies are listed 'Best First'.
Symbol Table Madness
by chromatic (Archbishop) on Apr 05, 2000 at 21:57 UTC
    You're right, the post-interpolated line should read: *main::scott = "scot2"; Here's what I've been using to test my assumptions:
    #!/usr/bin/perl $test1 = "value of test1"; $test2 = "test1"; $test3 = "Why are you here?"; # refers to *main::test1 print "=>$main::{$test2}<=\n"; print "Original \$test1: ...$test1...\n"; $main::{$test2} = "test3"; # $main::{"test1"} = "test1"; print "\$test1 = >>", $test1, "<<\n"; print "Main package: ", $main::test1, "\n";
    As you can see, $main::{$test2} evaluates to a typeglob. Saying that $main::{$test2} = "test3" changes the scalar is technically incorrect. (Though it is what my previous answer would lead one to believe!)

    Dunno where that u came from. Maybe it's a mu?

      chromatic wrote:
      > As you can see, $main::{$test2} evaluates to a typeglob.
      Right; because a typeglob *is* an entry in the symbol table.

      > Saying that $main::{$test2} = > "test3" changes the scalar is technically incorrect.
      Sorry, did I say that?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found