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