Created
June 27, 2016 09:15
-
-
Save dolmen/f9de389b566751296c1666e417584c58 to your computer and use it in GitHub Desktop.
Equivalents of C++ 2016 "if statement with initializer", in Perl 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Equivalents of C++ 2016 "if statement with initializer", in Perl 5 | |
# http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html | |
# | |
if ((my $p = $m->try_emplace($key, $value)), !$p->second) { | |
FATAL("Element already registered") | |
} else { | |
process($p->second) | |
} | |
sub foo() { | |
if ((my $c = bar()) != SUCCESS) { | |
return $c | |
} | |
... | |
} | |
# Other examples | |
if ((my $x = 0) != 0) { | |
say $x | |
} else { | |
say $x-1 | |
} | |
# Unfortunately, $x escapes the "if" block, so this is not as strict as C++. | |
say $x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment