From: Gurusamy Sarathy Date: Tue, 15 Feb 2000 18:02:17 +0000 (+0000) Subject: incorrect docs about delete() (spotted by Martyn Pearce X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8216c1fd0621dcbe0b0a1523feab4e8ce49ccdeb;p=p5sagit%2Fp5-mst-13.2.git incorrect docs about delete() (spotted by Martyn Pearce ) p4raw-id: //depot/perl@5106 --- diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 740a2fb..ad4a8e7 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -549,15 +549,17 @@ The exists() and delete() builtins now work on simple arrays as well. The behavior is similar to that on hash elements. exists() can be used to check whether an array element has been -initialized without autovivifying it. If the array is tied, the -EXISTS() method in the corresponding tied package will be invoked. +initialized. This avoids autovivifying array elements that don't exist. +If the array is tied, the EXISTS() method in the corresponding tied +package will be invoked. delete() may be used to remove an element from the array and return it. The array element at that position returns to its unintialized state, so that testing for the same element with exists() will return false. If the element happens to be the one at the end, the size of -the array also shrinks by one. If the array is tied, the DELETE() method -in the corresponding tied package will be invoked. +the array also shrinks up to the highest element that tests true for +exists(), or 0 if none such is found. If the array is tied, the DELETE() +method in the corresponding tied package will be invoked. See L and L for examples. diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 88cbb0a..e8f4fe0 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -929,8 +929,9 @@ See also L, L, L. Given an expression that specifies a hash element, array element, hash slice, or array slice, deletes the specified element(s) from the hash or array. -If the array elements happen to be at the end of the array, the size -of the array will shrink by that number of elements. +In the case of an array, if the array elements happen to be at the end, +the size of the array will shrink to the highest element that tests +true for exists() (or 0 if no such element exists). Returns each element so deleted or the undefined value if there was no such element. Deleting from C<$ENV{}> modifies the environment. Deleting from @@ -939,7 +940,9 @@ from a Cd hash or array may not necessarily return anything. Deleting an array element effectively returns that position of the array to its initial, uninitialized state. Subsequently testing for the same -element with exists() will return false. See L. +element with exists() will return false. Note that deleting array +elements in the middle of an array will not shift the index of the ones +after them down--use splice() for that. See L. The following (inefficiently) deletes all the values of %HASH and @ARRAY: