On Fri, Jan 13, 2006 at 10:33:23PM +0000, Luke Palmer wrote:
> In perl 5:
> 
>     my @a = (1,2,3);
>     delete $a[1];
>     print exists $a[1];
> 
> This is false, whereas $a[0] and $a[2] do exist.  This is creepy.  Not
> only is it creepy, it raises a whole bunch of questions with
> nontrivial answers:
> 
>     * does [EMAIL PROTECTED] include nonexistent elements?
>     * does map iterate over nonexistent elements?
>     * how do you store nonexistence for native packed arrays
> 
> And, what I always say, if the proper abstractions are being used,
> then all decisions become obvious truths.  Since the answers to these
> are not obvious truths, proper abstractions must not be in use.
> 
> Anyway, I want this behavior to die.  Maybe we should get rid of
> .delete() on arrays, or maybe we should equate it with
> .splice($idx,1).

I'm not sure if it came in as a side effect of pseudohashes. Sadly I no
longer have access to the AIX box where I built perl 5.000, so I can't
check what really old perl 5 makes of it. I have this hunch that
using exists on an array element is not legal syntax.

I have this vague memory that there's an even weirder piece of emergent
behaviour with arrays and exists, but I can't remember what it is. Possibly
something to do with extending arrays, but checking the source for av_exists
I can't work out any way to make it do even stranger things. Maybe it was
just this:

#!perl -w

use strict;

sub check {
    my $array = shift;
    printf "%d:", scalar @$array;
    foreach (0..9) {
        print exists $array->[$_] ? " Y" : " n";
    }
    print "\n";
}

my @a;
check [EMAIL PROTECTED];

my @b = @a;
check [EMAIL PROTECTED];

$#a=5;
check [EMAIL PROTECTED];

@b = @a;
check [EMAIL PROTECTED];

__END__
0: n n n n n n n n n n
0: n n n n n n n n n n
6: n n n n n n n n n n
6: Y Y Y Y Y Y n n n n


Some undefs are more equal than others.

Nicholas Clark

Reply via email to