On Tue, Oct 7, 2008 at 4:09 PM, Rob Dixon <[EMAIL PROTECTED]> wrote: > John W. Krahn wrote: [snip] >> 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. > > Rob >
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. Best, -- j -------------------------------------------------- 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!