X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsub.pod;h=4329c161ff2175d668b7b4b2e4c5e92363a83f95;hb=f7686833794ab18a8c8729b0e836f6f14223ce97;hp=f1b87923efa327d0b2db14ba27320339401c023f;hpb=a2293a43268c593a8a95d38299057a646f0fb089;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsub.pod b/pod/perlsub.pod index f1b8792..4329c16 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -39,7 +39,7 @@ To call subroutines: Like many languages, Perl provides for user-defined subroutines. These may be located anywhere in the main program, loaded in from other files via the C, C, or C keywords, or -generated on the fly using C or anonymous subroutines (closures). +generated on the fly using C or anonymous subroutines. You can even call a function indirectly using a variable containing its name or a CODE reference. @@ -169,8 +169,8 @@ Do not, however, be tempted to do this: Like the flattened incoming parameter list, the return list is also flattened on return. So all you have managed to do here is stored -everything in C<@a> and made C<@b> an empty list. See L for alternatives. +everything in C<@a> and made C<@b> an empty list. See +L for alternatives. A subroutine may be called using an explicit C<&> prefix. The C<&> is optional in modern Perl, as are parentheses if the @@ -207,8 +207,8 @@ core, as are modules whose names are in all lower case. A function in all capitals is a loosely-held convention meaning it will be called indirectly by the run-time system itself, usually due to a triggered event. Functions that do special, pre-defined -things include C, C, C, C, C, and -C--plus all functions mentioned in L. +things include C, C, C, C, C, +C and C--plus all functions mentioned in L. =head2 Private Variables via my() @@ -357,7 +357,7 @@ A compilation error results otherwise. An inner block may countermand this with C. A C has both a compile-time and a run-time effect. At compile -time, the compiler takes notice of it. The principle usefulness +time, the compiler takes notice of it. The principal usefulness of this is to quiet C, but it is also essential for generation of closures as detailed in L. Actual initialization is delayed until run time, though, so it gets executed @@ -645,10 +645,6 @@ and in: all the subroutines are called in a list context. -The current implementation does not allow arrays and hashes to be -returned from lvalue subroutines directly. You may return a -reference instead. This restriction may be lifted in future. - =head2 Passing Symbol Table Entries (typeglobs) B: The mechanism described in this section was originally @@ -697,9 +693,11 @@ Despite the existence of C, there are still three places where the C operator still shines. In fact, in these three places, you I use C instead of C. -=over +=over 4 + +=item 1. -=item 1. You need to give a global variable a temporary value, especially $_. +You need to give a global variable a temporary value, especially $_. The global variables, like C<@ARGV> or the punctuation variables, must be Cized with C. This block reads in F, and splits @@ -716,7 +714,9 @@ in C<@Fields>. It particular, it's important to Cize $_ in any routine that assigns to it. Look out for implicit assignments in C conditionals. -=item 2. You need to create a local file or directory handle or a local function. +=item 2. + +You need to create a local file or directory handle or a local function. A function that needs a filehandle of its own must use C on a complete typeglob. This can be used to create new symbol @@ -746,7 +746,9 @@ a local alias. See L for more about manipulating functions by name in this way. -=item 3. You want to temporarily change just one element of an array or hash. +=item 3. + +You want to temporarily change just one element of an array or hash. You can Cize just one element of an aggregate. Usually this is done on dynamics: @@ -924,6 +926,22 @@ that absolutely must start with that character. The value passed as part of C<@_> will be a reference to the actual argument given in the subroutine call, obtained by applying C<\> to that argument. +You can also backslash several argument types simultaneously by using +the C<\[]> notation: + + sub myref (\[$@%&*]) + +will allow calling myref() as + + myref $var + myref @array + myref %hash + myref &sub + myref *glob + +and the first argument of myref() will be a reference to +a scalar, an array, a hash, a code, or a glob. + Unbackslashed prototype characters have special meanings. Any unbackslashed C<@> or C<%> eats all remaining arguments, and forces list context. An argument represented by C<$> forces scalar context. An