X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsyn.pod;h=29db5dafd55a0b7d9d860854db269af36c746740;hb=645252571da2008f8956d78323fb408c931f0665;hp=f90b8b376ef2f1f5686f3aedc47b97b0fa6618b8;hpb=25b991bf8caa94f23a64f9568f5ceee69781aa25;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index f90b8b3..29db5da 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -228,6 +228,9 @@ The following compound statements may be used to control flow: if (EXPR) BLOCK if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK + unless (EXPR) BLOCK + unless (EXPR) BLOCK else BLOCK + unless (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK LABEL while (EXPR) BLOCK LABEL while (EXPR) BLOCK continue BLOCK LABEL until (EXPR) BLOCK @@ -252,7 +255,11 @@ all do the same thing: The C statement is straightforward. Because BLOCKs are always bounded by curly brackets, there is never any ambiguity about which C an C goes with. If you use C in place of C, -the sense of the test is reversed. +the sense of the test is reversed. Like C, C can be followed +by C. C can even be followed by one or more C +statements, though you may want to think twice before using that particular +language construct, as everyone reading your code will have to think at least +twice before they can understand what's going on. The C statement executes the block as long as the expression is L. @@ -670,28 +677,31 @@ case to the next: =head3 Return value When a C statement is also a valid expression (e.g. -when it's the last statement of a block), it returns : +when it's the last statement of a block), it evaluates to : =over 4 =item * -An empty list as soon as an explicit C is encountered. +an empty list as soon as an explicit C is encountered. =item * -The value of the last evaluated expression of the successful +the value of the last evaluated expression of the successful C/C clause, if there's one. =item * -The value of the last evaluated expression of the C block if no -condition was true. +the value of the last evaluated expression of the C block if no +condition is true. =back -Note that, unlike C and C, both C and C always -themselves return an empty list. +In both last cases, the last expression is evaluated in the context that +was applied to the C block. + +Note that, unlike C and C, failed C statements always +evaluate to an empty list. my $price = do { given ($item) { when ([ 'pear', 'apple' ]) { 1 } @@ -700,7 +710,7 @@ themselves return an empty list. 'unknown'; } }; -C blocks can't currently be used as proper expressions. This +Currently, C blocks can't always be used as proper expressions. This may be addressed in a future version of perl. =head3 Switching in a loop