X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsub.pod;h=a38d05be254eebad78f97cbcec87ea450e75f2ce;hb=54f70fc60d33628464c2f1f4a555eb6764959916;hp=c83f2da3368967de088d35f07ac159fea2f86000;hpb=44a8e56aa037ed0f03f0506f6f85f5ed290c78e1;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsub.pod b/pod/perlsub.pod index c83f2da..a38d05b 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -48,8 +48,15 @@ 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 +references (predating L) to the actual scalar parameters. What +this means in practice is that when you explicitly modify C<$_[0]> et al., +you will be changing the actual arguments. As a result, all arguments +to functions are treated as lvalues. Any hash or array elements that are +passed to functions will get created if they do not exist (irrespective +of whether the function does modify the contents of C<@_>). This is +frequently a source of surprise. See L for an example. + +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 @@ -608,7 +615,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