diff options
author | Vincent Pit <perl@profvince.com> | 2010-05-19 22:59:58 +0200 |
---|---|---|
committer | Vincent Pit <perl@profvince.com> | 2010-05-19 22:59:58 +0200 |
commit | 6b8a2794cd62dd8d195b1d5c2699448cfd2be2c8 (patch) | |
tree | cb5dc0bb5f0427100f1c072013d908a7214a76e3 /pod | |
parent | d41251f59aab3f60d462a8d7c86b6bdb94ebb0c8 (diff) | |
parent | 25b991bf8caa94f23a64f9568f5ceee69781aa25 (diff) | |
download | perl-6b8a2794cd62dd8d195b1d5c2699448cfd2be2c8.tar.gz |
Merge branch 'vincent/rvalue_stmt_given' into blead
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlsyn.pod | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 6359df4e14..3a65b4e9d0 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<given> 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<break> is encountered. + +=item * + +The value of the last evaluated expression of the successful +C<when>/C<default> clause, if there's one. + +=item * + +The value of the last evaluated expression of the C<given> block if no +condition was true. + +=back + +Note that, unlike C<if> and C<unless>, both C<when> and C<default> 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<given> 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<given()>, you can use a C<foreach()> loop. |