[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: exists $foo[7] and delete $foo[7]



I'm cautiously in favor of this functionality, but I agree that people
who look at it for the first time will expect:

    @a = (0 .. 9);
    delete $a[5];
    $" = '|'; print "@a";

To result in "0|1|2|3|4|6|7|8|9", whereas currently it would return
"0|1|2|3|4||6|7|8|9". Thus, I'm actually voicing an opinion of DON'T
INCLUDE, at least for now.

For those who feel that this blurs true-ness and other array issues,
there is a pretty clear precedent in hash-dom:

perl -e '$hash{red} = undef; $bool = (exists $hash{red}) ? "exists" : \
     "does not exist"; print "Hash key <red> $bool\n"'
Hash key <red> exists

perl -e '$hash{red} = undef; $bool = (defined $hash{red}) ? "is defined" : \
     "is not defined"; print "Hash key <red> $bool\n"'
Hash key <red> is not defined

So there is a difference between applying exists() to a non-existent
hash key versus a key that has the value undef. Likewise, the
difference would also be there for arrays. We simply haven't been able
to access that difference prior to this patch. I understand the
reasoning for (delete $a[5]) not changing the length of @a (unless it
was the last element), but I think it will confuse people. In fact,
I'm sure of it. While I would like to see delete/exists for arrays,
the current implementation pretty much demands an immediate entry in
the FAQ for the inevitable question of, "Why didn't 'delete $a[5]'
shorten the array?".

I like the potential, but the well- (and strictly-) defined linear
nature of arrays will lead people to believe things like:

       $a[100] = '0-99 do not yet exist';
       # later in their code...
       exists $a[23] or die "Why not? \$a[100] exists!";

Randy
--
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray            | "NSA doesn't need a key to compromise security in
rjray@redhat.com        | Windows. Programs like Back Orifice can do it without
415-777-9810 x246       | any keys." --Bruce Schneier on the MS/NSA controversy


Follow-Ups from:
Bart Schuller <schuller@lunatech.com>
References to:
Mark-Jason Dominus <mjd@plover.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]