in reply to question about variabies/references (ignore my previous botched entry)
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.
|
|---|