4 ms·
I like what Perl does: it separates cases by making them look like regular blocks: given($cat_macro){ when(/OH HAI/){ say "ceiling cat
by jrockway 16y ago
I like what Perl does: it separates cases by making them look like regular blocks:
given($cat_macro){
when(/OH HAI/){
say "ceiling cat is watching you switch statements";
}
when(/OH NOES/){
die "FAIL";
}
default {
say "<picture of a walrus with a bucket>";
}
}
Pretty easy to follow the control flow, even when they aren't oneliners.
- markchristian 16y agoThat's not bad. I take it you you could have "when(foo or bar)" to handle multiple cases?
- chromatic 16y agogiven/when are better than that; see http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detail http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detai... for all of the possibilities.