@@ -306,7 +306,7 @@ There are also C<with> and C<without> statement modifiers:
306
306
= head1 X < when|control flow >
307
307
308
308
The C < when > block is similar to an C < if > block and either or both can be used
309
- in an outer block, they also both have a statement modifier form.
309
+ in an outer block, they also both have a " statement modifier form."
310
310
But there is a difference in how following code in the same, outer
311
311
block is handled: When the C < when > block is executed, control is passed to
312
312
the enclosing block and following statements are ignored; but when the C < if >
@@ -332,9 +332,22 @@ Should the C<if> and C<when> blocks above appear at file scope, following
332
332
statements would be executed in each case.
333
333
334
334
There is one other feature a C < when > has that C < if > doesn't: the C < when > 's boolean
335
- test defaults to C < $_ ~~ > while the C < if > 's does not.
335
+ context test defaults to C < $_ ~~ > while the C < if > 's does not. That has an effect on
336
+ how one uses the X in the C < when > block without a value for <$_> (it's 'Any' in
337
+ that case and Any smart matches on True: Any ~~ True => True). Consider the following:
336
338
337
- C < when > also has a statement modifier form which does not effect execution
339
+ = begin code :skip-test
340
+ {
341
+ my $a = 1;
342
+ my $b = True;
343
+ when $a { say 'a' }; # no output
344
+ when so $a { say 'a' } # a (in "so $a" 'so' coerces $a to Boolean context True
345
+ # which matches with Any)
346
+ when $b { say 'b' }; # b (b is True as defined so matches with Any)
347
+ }
348
+ = end code
349
+
350
+ Finally, C < when > 's statement modifier form does not effect execution
338
351
of following statements either inside or outside of another block:
339
352
340
353
= begin code :skip-test
0 commit comments