in reply to Re^2: Some Insights from a Traveler Between Languages
in thread Some Insights from a Traveler Between Languages
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:
my @array; my $arrayref=[] my @copy=@array; my $refcopy=$arrayref;
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 tomy @copy = @array;
the former says loudly that a new thing is being created where the latter could be doing anything.my $copy=$array->copy;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Some Insights from a Traveler Between Languages
by doom (Deacon) on Apr 24, 2005 at 21:18 UTC | |
by jonadab (Parson) on Apr 25, 2005 at 12:41 UTC | |
|
Re^4: Some Insights from a Traveler Between Languages
by Anonymous Monk on Apr 25, 2005 at 01:37 UTC |