laziness, impatience, and hubris | |
PerlMonks |
Re^2: Hash of Hashby Athanasius (Archbishop) |
on Feb 18, 2014 at 15:19 UTC ( [id://1075350]=note: print w/replies, xml ) | Need Help?? |
Hello IvanAK, And also we have difference between reference and anonymous reference (or not ? but i see a little difference ). Not really. You will find the built-in function ref useful here. Consider:
Output:
As you can see, there is no intrinsic difference between the first reference, which is to a named hash, and the second, which is to an anonymous hash. The difference is in the way the hashes are created, not in the references to them.1 My enigma here is what kind of reference or anonymous thing is $sales. $sales (a scalar variable) contains a reference to a hash. That hash happens to be an anonymous hash, because it was created that way. The values in its key-value pairs also happen to be references to hashes (and, again, those hashes were created anonymously). But that has nothing to do with what $sales is — simply, a reference to a hash. The “fat comma” operator => has nothing to do with creating references, it is just a convenient replacement for the comma which (1) stringifies the left-hand-side (under certain conditions) and (2) “is helpful in documenting the correspondence between keys and values in hashes, and other paired elements in lists.” — see Comma Operator. Hope that helps, 1Well, OK, there is an important difference in the reference counts of the hashes: for %hash the reference count is 2, for the anonymous hash referenced by $ref2 it is 1. But that applies to the underlying data structures, not to the reference values held by $ref1 and $ref2.
In Section
Seekers of Perl Wisdom
|
|