[dummy merge]
[p5sagit/p5-mst-13.2.git] / pod / perlsub.pod
index 2d3e666..6e2309d 100644 (file)
@@ -47,9 +47,17 @@ there's really no difference from the language's perspective.)
 
 Any arguments passed to the routine come in as the array @_.  Thus if you
 called a function with two arguments, those would be stored in C<$_[0]>
-and C<$_[1]>.  The array @_ is a local array, but its values are implicit
-references (predating L<perlref>) to the actual scalar parameters.  The
-return value of the subroutine is the value of the last expression
+and C<$_[1]>.  The array @_ is a local array, but its elements are
+aliases for the actual scalar parameters.  In particular, if an element
+C<$_[0]> is updated, the corresponding argument is updated (or an error
+occurs if it is not updatable).  If an argument is an array or hash
+element which did not exist when the function was called, that element is
+created only when (and if) it is modified or if a reference to it is
+taken.  (Some earlier versions of Perl created the element whether or not
+it was assigned to.)  Note that assigning to the whole array @_ removes
+the aliasing, and does not update any arguments.
+
+The return value of the subroutine is the value of the last expression
 evaluated.  Alternatively, a return statement may be used to specify the
 returned value and exit the subroutine.  If you return one or more arrays
 and/or hashes, these will be flattened together into one large
@@ -496,7 +504,7 @@ Even if you don't want to modify an array, this mechanism is useful for
 passing multiple arrays in a single LIST, because normally the LIST
 mechanism will merge all the array values so that you can't extract out
 the individual arrays.  For more on typeglobs, see
-L<perldata/"Typeglobs and FileHandles">.
+L<perldata/"Typeglobs and Filehandles">.
 
 =head2 Pass by Reference
 
@@ -608,7 +616,7 @@ If you're planning on generating new filehandles, you could do this:
     sub openit {
        my $name = shift;
        local *FH;
-       return open (FH, $path) ? \*FH : undef;
+       return open (FH, $path) ? *FH : undef;
     } 
 
 Although that will actually produce a small memory leak.  See the bottom
@@ -758,11 +766,15 @@ to make the world a better place.
 
 Functions with a prototype of C<()> are potential candidates for
 inlining.  If the result after optimization and constant folding is a
-constant then it will be used in place of calls to the function.
+constant then it will be used in place of new-style calls to the
+function.  Old-style calls (that is, calls made using C<&>) are not
+affected.
 
 All of the following functions would be inlined.
 
-    sub PI ()          { 3.14159 }
+    sub pi ()          { 3.14159 }             # Not exact, but close.
+    sub PI ()          { 4 * atan2 1, 1 }      # As good as it gets,
+                                               # and it's inlined, too!
     sub ST_DEV ()      { 0 }
     sub ST_INO ()      { 1 }