develooper Front page | perl.perl5.porters | Postings from August 2001

Re: ${^Index}

Thread Previous | Thread Next
Wolfgang Laun
August 2, 2001 11:28
Re: ${^Index}
Message ID:
Abigail wrote:
> Oh, but @keys = keys (@array) could be useful. It would be equivalent to:
>     @keys = grep {exists $array [$_]} $[ .. $#array;
> Similar, @values = values (@array) would be equivalent to:
>     @values = @array [grep {exists $array [$_]} $[ .. $#array];

Surely, then, you would also want each( @array ) to return only existing
elements? If you answer "no", then the equivalence as it exists between
the return values of keys/values(%hash) and each(%hash) would not hold
for arrays.

> It doesn't stretch my imagination at all to consider arrays and
> hashes almost the same - one uses strings to index, the other (small)
> non-negative integers in sequence. The fact that arrays give you
> an implicite ordering is just a small benefit in this point of view,
> and not a basic difference. I therefore don't mind at all if Perl
> has operators that do similar things on both arrays and hashes.

I agree: both are capable of representing a mapping f:K->V for certain
sets K. But I disagree when I take into account the pertinent sets of
access functions that come with arrays and hashes, respectively.

> What "each" would do if an array is spliced on is a minor detail

Thinking of the lot of operations on arrays that would have to be on the
lookout for some ongoing "each" (as Mark Mielke nicely summarized), it
is perhaps not so minor, and, considering that it is difficult to
imagine some meaningful algorithm making good use of such crufty
operations, rather annoying.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About