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

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



>You keep saying "array elements' scalar values" as though there
>were array elements that weren't scalar values.  Is there something
>I'm missing?

No.  Simply that scalar values occur in several places, including
in scalar variables like $scalar, as elements in $array[N] or
$hash{KEY}, or as temporary values in expression or return values
from functions.  I'd like that something I can do to a scalar value
in one place (e.g. defined) be applicable to a scalar value in all
places that scalar values can occur.

>>No, we've not been able to call delete() on anything but
>>hash elements before.

>But I thought the question was only about hashes.

So long as delete $hash{KEY} looks like a hash, it should walk like
a hash.  In that respect, then yes, this is about hashes -- even
if %hash happens to be a pseudohash.

>>Why do we *care* whether space for a scalar has ever been allocated
>>in an array?

>Because if it isn't, then one may not care to do anything with that
>element.


>>And if we do care so much about that, why don't we
>>care whether space for a scalar that's *not* in an array has ever
>>been allocated?  
>>
>>    @array = qw/zero one two three/, undef, 'five';
>>
>>Why do we care to distinguish between $array[4] and $array[17] above?

>$array[4] has been explicitly initialized with a value (undef).
>$array[17] hasn't.  One would expect to consider $array[17] as being
>"not there", whereas $array[4] is "there" because you gave it a
>value.

Hm... I don't think I agree.  In fact, this seems by induction to
lead to infinite levels of questioning.  Suppose I can tell the
difference between an element that I assigned undef to and one that
I didn't.  How do I return that element to the state of not having
been assigned something?  Having done that, how do I then distinguish
between (N=1) a missing value that's missing because I never ever
gave it a value, and one that's missing [N=2] because it used to
have a value but now I said it should be missing?   You can extend
this for all monotonically values of N greater than 2, and keep
inventing new functions or ways of asking the question.

Perhaps in the end, it should not matter in any fashion whatsoever
whether one has assigned undef or never assigned undef.
--tom

PS: what about:

	local $x[3];
    vs
	local $x[3] = undef();


Follow-Ups from:
"Mark Mielke" <markm@nortelnetworks.com>
Steve Fink <sfink@digital-integrity.com>

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