develooper Front page | perl.perl6.language | Postings from April 2006

[svn:perl6-synopsis] r8900 - doc/trunk/design/syn

From:
larry
Date:
April 21, 2006 11:14
Subject:
[svn:perl6-synopsis] r8900 - doc/trunk/design/syn
Message ID:
20060421181322.9B484CB9BC@x12.develooper.com
Author: larry
Date: Fri Apr 21 11:13:21 2006
New Revision: 8900

Modified:
   doc/trunk/design/syn/S05.pod

Log:
Fixed up "state $x ||= /.../" example a little more.


Modified: doc/trunk/design/syn/S05.pod
==============================================================================
--- doc/trunk/design/syn/S05.pod	(original)
+++ doc/trunk/design/syn/S05.pod	Fri Apr 21 11:13:21 2006
@@ -1063,12 +1063,17 @@
 
 =item *
 
-The Perl 5 C<?...?> syntax (I<match once>) was rarely used and can be
+The Perl 5 C<?...?> syntax (I<succeed once>) was rarely used and can be
 now emulated more cleanly with a state variable:
 
-    (state $x) ||= / pattern /;    # only matches first time
+    $result = do { state $x ||= m/ pattern /; }    # only matches first time
 
-To reset the pattern, simply say C<$x = 0>.
+To reset the pattern, simply say C<$x = 0>.  Though if you want C<$x> visible
+you'd have to avoid using a block:
+
+    $result = state $x ||= m/ pattern /;
+    ...
+    $x = 0;
 
 =back
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About