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

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





Larry Wall wrote:
> 
> Tom Christiansen writes:
> : Of course I'm serious.  Remember, indices aren't keys.  They're just
> : positions.  splice completely removes an entry from an array in a way
> : that undef will not, just as delete completely removes an entry from a
> : hash the way that undef will not.
> 
> I think they're keys.  They're just constrained to be numeric as
> a very valuable hint for optimization.  And in the case of built-in
> arrays, determining order.  But that doesn't necessarily apply to
> tied arrays.  A tied array could perfectly validly raise an exception
> on a pop().
> 
> : Now, could someone please tell me what to fill in for XXXXX?
> 
> Slightly more seriously, you draw it without the outer bars, leaving
> isolated patches of values, as befits a sparse array:
> 
>     ----------------    ----------------
>     |    |    |    |    |    |    |    |
>     ----------------    ----------------


I'm with Tom. delete on a real array ought to splice out that element.

given the conceptualism of arrays and hashes,
the only way you can maintain consistency between the two concepts
in a pseudo-hash is if you cannot delete/splice/remove any elements.

i.e. to maintain all the concepts, pseudohashes would have to be 
fixed size arrays.  

if delete is allowed on a pseudohash, please leave the weirdness
to the person using the pseudohash.  calling delete on a pseudohash
would set that element to 'undef because its deleted' or some
strangeness. and it would be the programmers responsibility to
figure it out.

delete on a normal array should splice out that element,
or its another weirdness to remember about perl.

Greg



Follow-Ups from:
"Matthias Urlichs" <smurf@noris.net>
Larry Wall <larry@wall.org>
pete@horus.cix.co.uk (Pete Jordan)
Nick Ing-Simmons <nick@ing-simmons.net>

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