File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ inside C<BUIDLALL>, but not inside C<BUILD>).
109
109
110
110
= head2 Whitespace in Regexes does not match literally
111
111
112
- $ perl6-e "say 'a b' ~~ /a b/"
112
+ $ perl6 -e "say 'a b' ~~ /a b/"
113
113
False
114
114
115
115
Whitespace in regexes is, by default, considered an optional filler without
@@ -123,5 +123,24 @@ Ways to match whitespace:
123
123
= item C < \h > , C < \v > for horizontal, vertical whitespace
124
124
= item with C < m:s/a b/ > or C < m:sigspace/a b/ > , the blank in the regexes matches arbitrary whitespace
125
125
126
+ = head1 Captures
126
127
128
+ = head2 Variables versus values/expressions in a Capture
129
+
130
+ Beginners might expect a variable in a C < Capture > to supply its current
131
+ value when that C < Capture > is later used. For example:
132
+
133
+ $perl6 -e 'my $a = 2; say($a, ++$a)'
134
+ 33
135
+
136
+ Here the C < Capture > contained the B < variable > C < $a > and the B < value > of the result
137
+ of the expression C < ++$a > . Since the C < Capture > must be reified before C < &say > can
138
+ use it, the C < ++$a > may happen before C < &say > gets C < $a > , and so it may already
139
+ be incremented.
140
+
141
+ Instead, use an expression that produces a value when you want a value.
142
+
143
+ $perl6 -e 'my $a = 2; say(+$a, ++$a)'
144
+ 23
145
+
127
146
= end pod
You can’t perform that action at this time.
0 commit comments