On Wed, Oct 8, 2008 at 11:24 AM, Rob Dixon <[EMAIL PROTECTED]> wrote: > Jay Savage wrote: >> On Tue, Oct 7, 2008 at 4:09 PM, Rob Dixon <[EMAIL PROTECTED]> wrote: >>> John W. Krahn wrote: >>>> >>>> Incorrect, delete does not remove array elements: >>>> >>>> $ perl -le'use Data::Dumper; my @a = "a".."d"; delete $a[1]; print >>>> Dumper [EMAIL PROTECTED]' >>>> $VAR1 = [ >>>> 'a', >>>> undef, >>>> 'c', >>>> 'd' >>>> ]; >>> >>> According to exists() it does. >> >> exists() lies, or is lied to. >> >> 'delete $array[$x]' does not mimic the behavior of 'splice(@array, $x, >> 1)', except in the special case where $x == $#array (and, I suppose $x >> == -1)...and even that doesn't always do what you expect. In >> particular, delete can occasionally delete more than you think it >> should. >> >> See perldoc -f delete for details. >> >> The important information in this context, though, is that delete() >> causes further tests of exists() to fail, but in most cases doesn't >> actually remove the element, because that would mean renumbering the >> indicies of the other array elements, which is what splice is for. > > The return value of exists() is the definition of whether an array or hash > elements exists. It does exactly what it is documented to do and does not lie. > > The idea of non-existent mid-range array elements is unusual, although there > is > at least Lua that does a similar thing. > > splice() cannot make array elements non-existent except when the length of the > array is changed and tail elements vanish. To expect delete() to behave the > same > way as splice() is to be dissatisfied with the Perl language definition: they > are different operations. > > Rob >
No argument. The definitions of exists is "tests positive for exists()," and a tautology is a thing which is tautological. In any case, I'm not dissatisfied with the behavior. As I said, this is why we have both delete and splice, which both have uses. But the issue I was responding to isn't whether the element exists, it was your rebuff of John's assertion that delete does not always remove the item, which is correct. The element may no longer *exist*, but it is not *removed* (that is, the *structure* of the array is not modified) unless there are no remaining elements that exist between the element being deleted and the final element of the array. In other cases "deleting an array element effectively returns that position of the array to its initial, uninitialized state." That is, the element continues float out there in the same existential limbo as the elements of pre-sized arrays. This distinction between canonical existence and logical existence--or perhaps more properly the distinction between the existence of an element and of a position--is important because, while useful, the distinction does have implications for the value of $#array, the return value of scalar(), and the behavior of while and foreach blocks, among others, not just the output of Data::Dumper. HTH, --jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!