typo fix
[p5sagit/p5-mst-13.2.git] / pod / perlfunc.pod
index 161ebaa..dbefd85 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) {
@@ -949,7 +953,7 @@ And so do these:
 
     delete @HASH{keys %HASH};
 
-    delete @ARRAY{0 .. $#ARRAY};
+    delete @ARRAY[0 .. $#ARRAY];
 
 But both of these are slower than just assigning the empty list
 or undefining %HASH or @ARRAY:
@@ -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,11 +1419,19 @@ 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.
 
+Given an expression that specifies the name of a subroutine,
+returns true if the specified subroutine has ever been declared, even
+if it is undefined.  Mentioning a subroutine name for exists or defined
+does not count as declaring it.
+
+    print "Exists\n"   if exists &subroutine;
+    print "Defined\n"  if defined &subroutine;
+
 Note that the EXPR can be arbitrarily complicated as long as the final
-operation is a hash or array key lookup:
+operation is a hash or array key lookup or subroutine name:
 
     if (exists $ref->{A}->{B}->{$key})         { }
     if (exists $hash{A}{B}{$key})      { }
@@ -1428,6 +1439,8 @@ operation is a hash or array key lookup:
     if (exists $ref->{A}->{B}->[$ix])  { }
     if (exists $hash{A}{B}[$ix])       { }
 
+    if (exists &{$ref->{A}{B}{$key}})   { }
+
 Although the deepest nested array or hash will not spring into existence
 just because its existence was tested, any intervening ones will.
 Thus C<$ref-E<gt>{"A"}> and C<$ref-E<gt>{"A"}-E<gt>{"B"}> will spring
@@ -1445,6 +1458,12 @@ release.
 See L<perlref/"Pseudo-hashes"> for specifics on how exists() acts when
 used on a pseudo-hash.
 
+Use of a subroutine call, rather than a subroutine name, as an argument
+to exists() is an error.
+
+    exists &sub;       # OK
+    exists &sub();     # Error
+
 =item exit EXPR
 
 Evaluates EXPR and exits immediately with that value.    Example:
@@ -2785,6 +2804,34 @@ declared global variable without qualifying it with a package name.
 (But only within the lexical scope of the C<our> declaration.  In this
 it differs from "use vars", which is package scoped.)
 
+An C<our> declaration declares a global variable that will be visible
+across its entire lexical scope, even across package boundaries.  The
+package in which the variable is entered is determined at the point
+of the declaration, not at the point of use.  This means the following
+behavior holds:
+
+    package Foo;
+    our $bar;          # declares $Foo::bar for rest of lexical scope
+    $bar = 20;
+
+    package Bar;
+    print $bar;                # prints 20
+
+Multiple C<our> declarations in the same lexical scope are allowed
+if they are in different packages.  If they happened to be in the same
+package, Perl will emit warnings if you have asked for them.
+
+    use warnings;
+    package Foo;
+    our $bar;          # declares $Foo::bar for rest of lexical scope
+    $bar = 20;
+
+    package Bar;
+    our $bar = 30;     # declares $Bar::bar for rest of lexical scope
+    print $bar;                # prints 30
+
+    our $bar;          # emits warning
+
 =item pack TEMPLATE,LIST
 
 Takes a LIST of values and converts it into a string using the rules