This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
\R can't be used in a char class
[perl5.git] / pod / perlsyn.pod
index 31b919e..c10d732 100644 (file)
@@ -237,7 +237,7 @@ 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 C<while> statement executes the block as long as the expression is
-true (does not evaluate to the null string C<""> or C<0> or C<"0">).
+L<true|/"Truth and Falsehood">.
 The C<until> statement executes the block as long as the expression is
 false.
 The LABEL is optional, and if present, consists of an identifier followed
@@ -516,7 +516,7 @@ This construct is very flexible and powerful. For example:
        when (undef) {
            say '$foo is undefined';
        }
-
+       
        when ("foo") {
            say '$foo is the string "foo"';
        }
@@ -524,8 +524,8 @@ This construct is very flexible and powerful. For example:
        when ([1,3,5,7,9]) {
            say '$foo is an odd digit';
            continue; # Fall through
-    }
-
+       }
+       
        when ($_ < 100) {
            say '$foo is numerically less than 100';
        }
@@ -533,7 +533,7 @@ This construct is very flexible and powerful. For example:
        when (\&complicated_check) {
            say 'complicated_check($foo) is true';
        }
-
+       
        default {
            die q(I don't know what to do with $foo);
        }
@@ -698,7 +698,9 @@ order, determines the match behaviour.
 
  + - this must be a code reference whose prototype (if present) is not ""
      (subs with a "" prototype are dealt with by the 'Code()' entry lower down)
- * - if a circular reference is found, we fall back to referential equality
+ * - that is, each element matches the element of same index in the other
+     array. If a circular reference is found, we fall back to referential
+     equality.
  ! - either a real number, or a string that looks like a number
 
 The "matching code" doesn't represent the I<real> matching code,
@@ -711,6 +713,34 @@ You can change the way that an object is matched by overloading
 the C<~~> operator. This trumps the usual smart match semantics.
 See L<overload>.
 
+=head3 Differences from Perl 6
+
+The Perl 5 smart match and C<given>/C<when> constructs are not
+absolutely identical to their Perl 6 analogues. The most visible
+difference is that, in Perl 5, parentheses are required around
+the argument to C<given()> and C<when()>. Parentheses in Perl 6
+are always optional in a control construct such as C<if()>,
+C<while()>, or C<when()>; they can't be made optional in Perl
+5 without a great deal of potential confusion, because Perl 5
+would parse the expression
+
+  given $foo {
+    ...
+  }
+
+as though the argument to C<given> were an element of the hash
+C<%foo>, interpreting the braces as hash-element syntax.
+
+The table of smart matches is not identical to that proposed by the
+Perl 6 specification, mainly due to the differences between Perl 6's
+and Perl 5's data models.
+
+In Perl 6, C<when()> will always do an implicit smart match
+with its argument, whilst it is convenient in Perl 5 to
+suppress this implicit smart match in certain situations,
+as documented above. (The difference is largely because Perl 5
+does not, even internally, have a boolean type.)
+
 =head2 Goto
 X<goto>