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

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



>On Thu, Jan 13, 2000 at 11:54:35AM -0800, "Gurusamy Sarathy" wrote:
>> On Thu, 13 Jan 2000 12:36:51 MST, Tom Christiansen wrote:
>> >>>Will delete allow for
>> >>>    delete $a[100];
>> >>>    print scalar @a;    # prints 0 ???
>> >>Yes, that's what it does.
>> >So, delete on an array doesn't actually do the same thing as
>> >pop/splice/shift would.  I don't think that this won't confuse
>> >people.  Do you not not think not either? :-)
>> I think it would confuse people who are willingly/easily confused,
>> yes.

>Which is really true for almost anything perl. No point in looking back now.

Sigh.  No, it's not like that.  I'm always showing pictures like this

    Before:

	    0     1      2      3      4    
	+------+------+------+------+------+
	+Every | Good | Boy  | Does | Fine |
	+------+------+------+------+------+

    Muckage:

	splice(@array, 1, 1);

    After:


	    0     1      2      3     
	+------+------+------+------+
	+Every | Boy  | Does | Fine |
	+------+------+------+------+


And likewise, 


    Before:

	    +-----+-----+
	    |  K  | 19  |
	    +-----+-----+
	    | Li  | 11  |
	    +-----+-----+
	    |  H  |  1  |
	    +-----+-----+
	    | Ca  | 38  |
	    +-----+-----+
	    |  C  | 14  |
	    +-----+-----+

    Muckage:

	    undef $hash{Ca};

    After:

	    +-----+-----+
	    |  K  | 19  |
	    +-----+-----+
	    | Li  | 11  |
	    +-----+-----+
	    |  H  |  1  |
	    +-----+-----+
	    | Ca  |undef|
	    +-----+-----+
	    |  C  | 14  |
	    +-----+-----+

And constrast that with 

    Before:

	    +-----+-----+
	    |  K  | 19  |
	    +-----+-----+
	    | Li  | 11  |
	    +-----+-----+
	    |  H  |  1  |
	    +-----+-----+
	    | Ca  |undef|
	    +-----+-----+
	    |  C  | 14  |
	    +-----+-----+

    Muckage:

	    delete $hash{Li};

    After:

	    +-----+-----+
	    |  K  | 19  |
	    +-----+-----+
	    |  H  |  1  |
	    +-----+-----+
	    | Ca  |undef|
	    +-----+-----+
	    |  C  | 14  |
	    +-----+-----+


Now, if you stand your array on end, and make like its numeric indices
are in the keys' slots:

    Before:

	          +-----+
	       0  |Every|
	          +-----+
	       1  |Good |
	          +-----+
	       2  |Boy  |
	          +-----+
	       3  |Does |
	          +-----+
	       4  |Fine |
	          +-----+

    Muckage:

	undef $a[1];


    After:

	          +-----+
	       0  |Every|
	          +-----+
	       1  |undef|
	          +-----+
	       2  |Boy  |
	          +-----+
	       3  |Does |
	          +-----+
	       4  |Fine |
	          +-----+

Then I show this in constrast with  

    Muckage:

	splice(@array, 1, 1);

    After:

	          +-----+
	       0  |Every|
	          +-----+
	       1  |Boy  |
	          +-----+
	       2  |Does |
	          +-----+
	       3  |Fine |
	          +-----+

This is nice and parallel.  splice() to an array is delete() to a
hash.  Well, I sure thought it was.  Isn't it?  I don't really
understand how to modify this for the proposed behaviour of delete
$array[1].  Please help me out here.

    Before:

	          +-----+
	       0  |Every|
	          +-----+
	       1  |Good |
	          +-----+
	       2  |Boy  |
	          +-----+
	       3  |Does |
	          +-----+
	       4  |Fine |
	          +-----+

    Muckage:

	delete $a[1];


    After:

	          +-----+
	       0  |Every|
	          +-----+
	       1  |XXXXX|
	          +-----+
	       2  |Boy  |
	          +-----+
	       3  |Does |
	          +-----+
	       4  |Fine |
	          +-----+

What goes in for XXXXX?  I can't put undef, now can I?  But isn't
that what's there?  Except, this particular undef is different than
the one we got via assignment.  It is, as I dimly apprehend it,  a
*special* flavor of undef, isn't it?  But isn't undef already a
special flavor of false?

--tom


Follow-Ups from:
Bart Schuller <schuller@lunatech.com>

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