X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsub.pod;h=6e2309dfb22d6e5fdcc80cca2d2e1d08abff980c;hb=d03407ef6d8e534a414e9ce92c6c5c8dab664a40;hp=9d725abe0d2adbd75bdabe285e031f706d769eef;hpb=2ae324a7ad5d4e616e757c311984fd86d5857ddd;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsub.pod b/pod/perlsub.pod index 9d725ab..6e2309d 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -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) 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 @@ -764,7 +772,9 @@ 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 }