clearer docs for change#4796; faster av_exists()
authorGurusamy Sarathy <gsar@cpan.org>
Thu, 13 Jan 2000 08:12:56 +0000 (08:12 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Thu, 13 Jan 2000 08:12:56 +0000 (08:12 +0000)
p4raw-link: @4796 on //depot/perl: 010205895f86f073b0b2a20bd4cfbb05f0134888

p4raw-id: //depot/perl@4797

av.c
pod/perldelta.pod
pod/perldiag.pod
pod/perlfunc.pod

diff --git a/av.c b/av.c
index 3b7e813..af8296a 100644 (file)
--- a/av.c
+++ b/av.c
@@ -663,8 +663,11 @@ Perl_av_exists(pTHX_ AV *av, I32 key)
            return SvTRUE(sv);
        }
     }
-    if (av_fetch(av, key, 0))
+    if (key <= AvFILLp(av) && AvARRAY(av)[key] != &PL_sv_undef
+       && AvARRAY(av)[key])
+    {
        return TRUE;
+    }
     else
        return FALSE;
 }
index b205c74..9c040ed 100644 (file)
@@ -430,13 +430,15 @@ required for C<foo(10)->('bar')>.
 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 exists without
-autovivifying it.  If the array is tied, the EXISTS() method in the
-corresponding tied package will be invoked.
-
-delete() may now be used to remove an element from the array and return
-it.  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
+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.
+
+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.
 
 See L<perlfunc/exists> and L<perlfunc/delete> for examples.
index 20ab4d9..f82cd25 100644 (file)
@@ -140,23 +140,23 @@ definition ahead of the call to get proper prototype checking.  Alternatively,
 if you are certain that you're calling the function correctly, you may put
 an ampersand before the name to avoid the warning.  See L<perlsub>.
 
-=item %s argument is not a HASH element
+=item %s argument is not a HASH or ARRAY element
 
-(F) The argument to exists() must be a hash element, such as
+(F) The argument to exists() must be a hash or array element, such as:
 
     $foo{$bar}
-    $ref->[12]->{"susie"}
+    $ref->[12]->["susie"]
 
-=item %s argument is not a HASH element or slice
+=item %s argument is not a HASH or ARRAY element or slice
 
-(F) The argument to delete() must be either a hash element, such as
+(F) The argument to delete() must be either a hash or array element, such as:
 
     $foo{$bar}
-    $ref->[12]->{"susie"}
+    $ref->[12]->["susie"]
 
-or a hash slice, such as
+or a hash or array slice, such as:
 
-    @foo{$bar, $baz, $xyzzy}
+    @foo[$bar, $baz, $xyzzy]
     @{$ref->[12]}{"susie", "queue"}
 
 =item %s did not return a true value
index 161ebaa..90c1988 100644 (file)
@@ -935,6 +935,10 @@ element.  Deleting from C<$ENV{}> modifies the environment.  Deleting from
 a hash tied to a DBM file deletes the entry from the DBM file.  Deleting
 from a C<tie>d 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</exists>.
+
 The following (inefficiently) deletes all the values of %HASH and @ARRAY:
 
     foreach $key (keys %HASH) {
@@ -970,7 +974,6 @@ lookup:
     delete $ref->[$x][$y][$index];
     delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
 
-
 =item die LIST
 
 Outside an C<eval>, prints the value of LIST to C<STDERR> and
@@ -1404,9 +1407,9 @@ any C<DESTROY> methods in your objects.
 =item exists EXPR
 
 Given an expression that specifies a hash element or array element,
-returns true if the specified element exists in the hash or array,
-even if the corresponding value is undefined.  The element is not
-autovivified if it doesn't exist.
+returns true if the specified element in the hash or array has ever
+been initialized, even if the corresponding value is undefined.  The
+element is not autovivified if it doesn't exist.
 
     print "Exists\n"   if exists $hash{$key};
     print "Defined\n"  if defined $hash{$key};
@@ -1416,7 +1419,7 @@ autovivified if it doesn't exist.
     print "Defined\n"  if defined $array[$index];
     print "True\n"      if $array[$index];
 
-A hash element can be true only if it's defined, and defined if
+A hash or array element can be true only if it's defined, and defined if
 it exists, but the reverse doesn't necessarily hold true.
 
 Note that the EXPR can be arbitrarily complicated as long as the final