Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
You're seeing this weird behavior because you have several variables that point to the same value; at the time of the first print, you haven't yet set that value, so it's undefined. When you set the value in the next line, it sets that value, so when you do the second print, they have a value.

Let's step through it:

$test = "scott";
This is self-explanatory--you're just setting a scalar variable. Later you'll use that value as a symbolic reference.
$main::{$test} = "skot2";
Here you're manipulating the symbol table; you're saying that $main::scott should point to the same thing that $main::skot2 points to. You can do this symbol table manipulation quite easily, and there's a definite potential for confusion--for example, there's a difference between $main::{"scott"} and $main::scott. The first is a symbol table entry and the second is a scalar variable.
print "As you see, ($scott) and ($main::scott) " . "aren't here\n";
$scott and $main::scott are the same variable, because $scott is found in package main, and the second is just a fully-qualified version of the first. You haven't set a value for this variable yet. You've modified $main::{"scott"} but not $main::scott. Perhaps that's the real source of your confusion?
$$test = "surprise!";
Here's where you set the value. $test is equal to "scott", so here you're just using symbolic references to change the value of $scott (which is the same as $main::scott and points to $skot2). So, it makes sense that, in the next line...
print "Now ($scott) and ($skot2) and ($main::scott) " . "have decided to show up\n";
you now have values for your variables.

Does this make sense?


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (11)
    As of 2014-07-31 11:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (248 votes), past polls