X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/d41251f59aab3f60d462a8d7c86b6bdb94ebb0c8..6b8a2794cd62dd8d195b1d5c2699448cfd2be2c8:/pod/perlsyn.pod diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 6359df4..3a65b4e 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -674,6 +674,42 @@ case to the next: default { say '$foo does not contain a y' } } +=head3 Return value + +When a C statement is also a valid expression (e.g. +when it's the last statement of a block), it returns : + +=over 4 + +=item * + +An empty list as soon as an explicit C is encountered. + +=item * + +The value of the last evaluated expression of the successful +C/C clause, if there's one. + +=item * + +The value of the last evaluated expression of the C block if no +condition was true. + +=back + +Note that, unlike C and C, both C and C always +themselves return an empty list. + + my $price = do { given ($item) { + when ([ 'pear', 'apple' ]) { 1 } + break when 'vote'; # My vote cannot be bought + 1e10 when /Mona Lisa/; + 'unknown'; + } }; + +C blocks can't currently be used as proper expressions. This +may be addressed in a future version of perl. + =head3 Switching in a loop Instead of using C, you can use a C loop.