Testing has some disadvantages....
...it's possible that a particular piece of code may be ambigious - meaning that the compiler writer can choose how to implement it.
So, simply "testing it" isn't always a solution.
However, in this case, the question of what is happening (and why) require first understanding what did happen. (Thus, "test it")
My rambling non-official option:
- scalars are probably implemented as pointers (they point to something) with logic to do necessary things, such as convert between integer and characters on the fly
- arrays are a structure, with each element being a scalar.
- hashes are a structure (same as array), except that key and value are scalars
So...an array and a hash cannot be a member of an array or hash. (Back to that whole reference thing).
@xxx = (1, 2, 3); --- creates an array xxx and give its the values to the list (1,2,3) (lists and arrays are different - lists are a collection of scalars, lacking the structure of an array. ie: can't get a size of a list, iirc)
$rx = [1,2,3]; --- the [] create an anonymous array (ie: this IS an array). and allows the $rx to reference this array.
so
@xxx = (1,2,3), $rx = \\@xxx; is very different from
@xxx = (1,2,3), $rx = [1,2,3]; (there are 2 arrays created in the 2nd example).
now...to really play with your mind, 2 things....
- You can create N number of references to a variable...
$reference4 = \\\\\\\\"hello!";
How to reference this reference to a reference to a reference?
print $$$$$refenence4;
- Perl also has Symbolic references -
$variablex = 1;
$symbolic_x = "variablex";
print $$symbolic_x;