in reply to RE: Re: Is this a hash? or what?
in thread Is this a hash? or what?
Thanks
References are the Perl abstraction of pointers. That is not to say that references are pointers (They most certainly are not) but to say that you can usually think of them as such.
This is a statement I hear a lot, and I just don't get it. While references certainly _ARE_ Perl's abstraction of pointers, the use of them is so different that the comparison isn't really worth making. Pointers can be manipulated, references can't. (You noted that). If I can't do pointer operations on a reference, why pull in all the pointer baggage (While learning pointers wasn't conceptually hard for me, in practice they were the hardest CS concept for me to get working)
I think you under-sell the power of references by just saying that they are a way to nest data structures.
Okay, guilty as charged.
But you can de-reference it later. Or pass it to a subroutine, or store a collection of arrays in a hash by storing their references (but don't try to use references as hash keys... Perl converts them to a string for you, but won't reverse the process.)
All true. So how is the following as a short description (basically saying what you said without bringing in pointers):
"References are scalars that refer to a perl data structure. They can be de-referenced, which gives you the data structure. Because Perl data structures are normally "flat" (An array element or hash value can only be scalar), this allows you to creat nested data structures. Because perl subroutines are passed 1 list of parameters, it allows you to call a subroutine with multiple arrays, hashes, and even references to other subroutines. References are the backbone of modules, which change perl from a good scripting language into a powerful programming language."
|
|---|