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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This has to be one of the best questions I've seen here, if only for the reson that it gave me a good chance to go digging around and try to figure this out. This explanation is far from perfect and any additions/corrections are welcome.

The main problem comes with the line $main::{$test} = "skot2". This is a lookup into the symbol table of main::, with the key of $test. Perl stores its symbol table in the form of string keys, and typeglob values. $main::{$test} is not the same as the $$test a couple lines down, but rather is the same as $::{$test}.

As for the weirdness in the last line, with $scott and $skot2 now being the same value, the $main::{$test} = "skot2" line again needs to be looked at. The main:: symbol table is expecting a typeglob or a reference on assignment, but when perl is expecting a typeglob and gets a string, it automatically creates a new typeglob of that name, so that line is functionally equivalent to having put $main::{$test} = *skot2. This is effect creates an alias between $scott and $skot2, so changes to either one will affect the other.

What needs to be done to get any kind of sensible answer is to pass in a reference on the assignment to $main::{$test}. There are two ways to go about it. Either you can do $main::{$test} = \"skot2", which will make the value of $scott come out right, but will make it be a constant, and thus the assignment to $$test will fail. The better way to do it would be to assign the value "skot2" to another variable, and pass in the reference of that variable.

Hope this helps.


In reply to Re: question about variabies/references (ignore my previous botched entry) by plaid
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found