This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Note changes to perlvar in perldelta
[perl5.git] / pod / perlsyn.pod
index f90b8b3..18143d1 100644 (file)
@@ -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<if> statement is straightforward.  Because BLOCKs are always
 bounded by curly brackets, there is never any ambiguity about which
 C<if> an C<else> goes with.  If you use C<unless> in place of C<if>,
-the sense of the test is reversed.
+the sense of the test is reversed. Like C<if>, C<unless> can be followed
+by C<else>. C<unless> can even be followed by one or more C<elsif>
+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<while> statement executes the block as long as the expression is
 L<true|/"Truth and Falsehood">.
@@ -670,28 +677,31 @@ case to the next:
 =head3 Return value
 
 When a C<given> 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<break> is encountered.
+an empty list as soon as an explicit C<break> is encountered.
 
 =item *
 
-The value of the last evaluated expression of the successful
+the value of the last evaluated expression of the successful
 C<when>/C<default> clause, if there's one.
 
 =item *
 
-The value of the last evaluated expression of the C<given> block if no
-condition was true.
+the value of the last evaluated expression of the C<given> block if no
+condition is true.
 
 =back
 
-Note that, unlike C<if> and C<unless>, both C<when> and C<default> always
-themselves return an empty list.
+In both last cases, the last expression is evaluated in the context that
+was applied to the C<given> block.
+
+Note that, unlike C<if> and C<unless>, failed C<when> 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<given> blocks can't currently be used as proper expressions. This
+Currently, C<given> blocks can't always be used as proper expressions. This
 may be addressed in a future version of perl.
 
 =head3 Switching in a loop
@@ -921,7 +931,7 @@ C preprocessors: it matches the regular expression
     # example: '# line 42 "new_filename.plx"'
     /^\#   \s*
       line \s+ (\d+)   \s*
-      (?:\s("?)([^"]+)\2)? \s*
+      (?:\s("?)([^"]+)\g2)? \s*
      $/x
 
 with C<$1> being the line number for the next line, and C<$3> being