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
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
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
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 }