Don't ask to ask, just ask | |
PerlMonks |
Re^3: Some Insights from a Traveler Between Languagesby demerphq (Chancellor) |
on Apr 24, 2005 at 17:36 UTC ( [id://451006]=note: print w/replies, xml ) | Need Help?? |
In a language like Perl, it's not clear to me that the distinction between "array" and "array ref" is a useful one. IMO its a pretty useful distinction. For instance:
So now what happens to the thing $arrayref references when when we modify $refcopy->[0]? It changes. What happens to @array when we modify $copy[0]. Nothing. The point is that you can determine many things about manipulating an object by its sigil. For instance a copy of a ref is cheap, a copy of an array is not. Modifying the contents of a ref will change the results of all things using the same ref. Modifing the contents of an array will only change that array or things that reference it. Maybe im too close to the trees but I see a big difference between them and good reasons to have both. Sure you can provide all the same effects with only references (provided you have a way to clone/copy an array) but there is a lot to be said for making them visually distinct. I mean personally i find to be preferable to the former says loudly that a new thing is being created where the latter could be doing anything.
--- demerphq
In Section
Meditations
|
|