From: Jarkko Hietaniemi Date: Thu, 5 Nov 1998 14:24:33 +0000 (+0000) Subject: Document all the control flow keywords in perlfunc X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a189bff91e12f37f676ca8e82c32442607e0976b;p=p5sagit%2Fp5-mst-13.2.git Document all the control flow keywords in perlfunc so that "perlfunc -f while" works. p4raw-id: //depot/cfgperl@2205 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index df34877..bd83dc3 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -135,8 +135,10 @@ C, C =item Keywords related to the control flow of your perl program -C, C, C, C, C, C, C, -C, C, C, C, C, C, C +C, C, C, C, C, C, C, +C, C, C, C, C, C, C, +C, C, C, C, C, C, +C, C =item Keywords related to scoping @@ -671,14 +673,14 @@ L. =item continue BLOCK Actually a flow control statement rather than a function. If there is a -C BLOCK attached to a BLOCK (typically in a C or -C), it is always executed just before the conditional is about to -be evaluated again, just like the third part of a C loop in C. Thus +C BLOCK attached to a BLOCK (typically in a L<(while> or +L), it is always executed just before the conditional is about to +be evaluated again, just like the third part of a L loop in C. Thus it can be used to increment a loop variable, even when the loop has been continued via the C statement (which is similar to the C C statement). -C, C, or C may appear within a C +L, L, or L may appear within a C block. C and C will behave as if they had been executed within the main block. So will C, but since it will execute a C block, it may be more entertaining. @@ -697,6 +699,8 @@ Omitting the C section is semantically equivalent to using an empty one, logically enough. In that case, C goes directly back to check the condition at the top of the loop. +See also L. + =item cos EXPR Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, @@ -942,11 +946,12 @@ as the first line of the handler (see L). Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by a loop -modifier, executes the BLOCK once before testing the loop condition. -(On other statements the loop modifiers test the conditional first.) +modifier such as L or L, executes the BLOCK once +before testing the loop condition. (On other statements the loop +modifiers test the conditional first.) C does I count as a loop, so the loop control statements -C, C or C cannot be used to leave or restart the block. +L, L or L cannot be used to leave or restart the block. =item do SUBROUTINE(LIST) @@ -1061,6 +1066,12 @@ only in a different order: See also C and C. +=item else BLOCK + +=item elsif (EXPR) BLOCK + +See L. + =item eof FILEHANDLE =item eof () @@ -1432,6 +1443,38 @@ Here's a mailbox appender for BSD systems. See also L for other flock() examples. +=item for (INITIAL; WHILE; EACH) BLOCK + +Do INITIAL, enter BLOCK while EXPR is true, at the end of each round +do EACH. For example: + + for ($i = 0, $j = 0; $i < 10; $i++) { + if ($i % 3 == 0) { $j++ } + print "i = $i, j = $j\n"; + } + +See L for more details. See also L, a twin of +C, L and L, close cousins of L, and +L, L, and L for additional control flow. + +=item foreach LOOPVAR (LIST) BLOCK + +Enter BLOCK as LOOPVAR set in turn to each element of LIST. +For example: + + foreach $rolling (@stones) { print "rolling $stone\n" } + + foreach my $file (@files) { print "file $file\n" } + +The LOOPVAR is optional and defaults to C<$_>. If the elements are +modifiable (as opposed to constants or tied variables) you can modify them. + + foreach (@words) { tr/abc/xyz/ } + +See L for more details. See also L, a twin of +C, L and L, close cousins of L, and +L, L, and L for additional control flow. + =item fork Does a fork(2) system call. Returns the child pid to the parent process, @@ -1838,6 +1881,21 @@ see L.) If EXPR is omitted, uses C<$_>. print hex '0xAf'; # prints '175' print hex 'aF'; # same +=item if (EXPR) BLOCK + +=item if (EXPR) BLOCK else BLOCK2 + +=item if (EXPR) BLOCK elsif (EXPR2) BLOCK2 + +Enter BLOCKs conditionally. The first EXPR to return true +causes the corresponding BLOCK to be entered, or, in the case +of C, the fall-through default BLOCK. + +Take notice: Perl wants BLOCKS, expressions (like e.g. in C, C++, or +Pascal) won't do. + +See L for more details. See also C. + =item import There is no builtin C function. It is just an ordinary @@ -1999,8 +2057,10 @@ C block, if any, is not executed: C cannot be used to exit a block which returns a value such as C, C or C. -See also L for an illustration of how C, C, and -C work. +See also L for an illustration of how C, L, and +L work. + +See also L. =item lc EXPR @@ -2210,8 +2270,10 @@ refers to the innermost enclosing loop. C cannot be used to exit a block which returns a value such as C, C or C. -See also L for an illustration of how C, C, and -C work. +See also L for an illustration of how L, C, and +L work. + +See also L. =item no Module LIST @@ -2825,7 +2887,7 @@ See L for examples. =item redo The C command restarts the loop block without evaluating the -conditional again. The C block, if any, is not executed. If +conditional again. The L block, if any, is not executed. If the LABEL is omitted, the command refers to the innermost enclosing loop. This command is normally used by programs that want to lie to themselves about what was just input: @@ -2850,9 +2912,11 @@ themselves about what was just input: C cannot be used to retry a block which returns a value such as C, C or C. -See also L for an illustration of how C, C, and +See also L for an illustration of how L, L, and C work. +See also L. + =item ref EXPR =item ref @@ -4205,8 +4269,6 @@ not trying to restrict access for yourself, returns C. Remember that a umask is a number, usually given in octal; it is I a string of octal digits. See also L, if all you have is a string. - - =item undef EXPR =item undef @@ -4233,6 +4295,13 @@ parameter. Examples: Note that this is a unary operator, not a list operator. +=item unless (EXPR) BLOCK + +The negative counterpart of L. If the EXPR returns false the +BLOCK is entered. + +See also L. + =item unlink LIST =item unlink @@ -4282,10 +4351,6 @@ The following efficiently counts the number of set bits in a bit vector: $setbits = unpack("%32b*", $selectmask); -=item untie VARIABLE - -Breaks the binding between a variable and a package. (See C.) - =item unshift ARRAY,LIST Does the opposite of a C. Or the opposite of a C, @@ -4298,6 +4363,21 @@ Note the LIST is prepended whole, not one element at a time, so the prepended elements stay in the same order. Use C to do the reverse. +=item until (EXPR) BLOCK + +=item do BLOCK until (EXPR) + +Enter BLOCK until EXPR returns false. The first form may avoid entering +the BLOCK, the second form enters the BLOCK at least once. + +See L, L, and L. + +See also L. + +=item untie VARIABLE + +Breaks the binding between a variable and a package. (See C.) + =item use Module LIST =item use Module @@ -4514,6 +4594,15 @@ warnings (even the so-called mandatory ones). An example: See L for details on setting C<%SIG> entries, and for more examples. +=item while (EXPR) BLOCK + +=item do BLOCK while (EXPR) + +Enter BLOCK while EXPR is true. The first form may avoid entering the +BLOCK, the second form enters the BLOCK at least once. + +See also L, L, L, and L. + =item write FILEHANDLE =item write EXPR