[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: arrays: delete()/exists() + possible keys()/values()
"Mark Mielke" <markm@nortelnetworks.com> writes:
> Let's see... what were the other operators? each()?
>
> my @a;
> $a[5] = 2;
> $a[7] = 3;
> while (($k, $v) = each @a) {
> print "\$a[$k] = $v;\n";
> }
>
> Would Print:
>
> $a[5] = 2;
> $a[7] = 3;
I've often thought about things like:
my @a = (1, 2, 3, 4);
my %a = @a;
followed somewhere by a keys %a. With the discussion of exists and
delete on arrays, I've started thinking more about what keys and
values should return on an array. It seems there are two schools of
thought -- it should return the valid indexes, or it should return the
even/odd indexed elements.
Example:
if @a = (10, 20, 30, 40), then keys(@a) would be (10, 30). Likewise
values(@a) would be (20, 40). each(@a) would basically return pairs
of array entries as it moves down the list.
The nice thing about this is that if...
my %a = @a;
Then we have keys(%a) being the same (except for ordering) as keys
@a. Likewise for values.
If keys(@a) returned the indexes, then it seems to me like we have two
aggregate types that we can assign to each other, yet keys returns
drastically different values for the aggregate type.
I feel low on tuits right now though :) Any thoughts?
Chip
--
Chip Turner chip@ZFx.com
Programmer, ZFx, Inc. www.zfx.com
PGP key available at wwwkeys.us.pgp.net
- Follow-Ups from:
-
"Mark Mielke" <markm@nortelnetworks.com>
- References to:
-
Tom Christiansen <tchrist@chthon.perl.com>
"Mark Mielke" <markm@nortelnetworks.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]