Skip to content

Commit 0ac8b6c

Browse files
committed
Improve with/orwith section examples
1 parent 9a5d617 commit 0ac8b6c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

doc/Language/control.pod

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,20 @@ truth. In addition, it topicalizes on the condition, much like C<given>:
264264
265265
with "abc".index("a") { .say } # prints 0
266266
267-
These may be cascaded:
267+
Instead of C<elsif>, C<orwith> may be used to chain definedness tests:
268268
269-
with $s.index("a") { "Found a at $_" }
270-
orwith $s.index("b") { "Found b at $_" }
271-
orwith $s.index("c") { "Found c at $_" }
272-
else { "Didn't find a, b or c" }
269+
# The below code says "Found a at 0"
270+
my $s = "abc";
271+
with $s.index("a") { say "Found a at $_" }
272+
orwith $s.index("b") { say "Found b at $_" }
273+
orwith $s.index("c") { say "Found c at $_" }
274+
else { say "Didn't find a, b or c" }
273275
274276
You may intermix C<if>-based and C<with>-based clauses.
275277
278+
# This says "Yes"
279+
if 0 { say "No" } orwith Nil { say "No" } orwith 0 { say "Yes" };
280+
276281
As with C<unless>, you may use C<without> to check for undefinedness,
277282
but you may not add an C<else> clause:
278283

0 commit comments

Comments
 (0)