G'day coolmichael,
Another potential option is to use nested ternary (?:) operators. Here's an example using your "Mostly the given/whens look like this" construct:
$ perl -Mstrict -Mwarnings -E ' use 5.018; no if $] >= 5.018, warnings => "experimental::smartmatch"; my @tests = qw{abc bar def foo}; say "*** Using given/when ***"; for my $foo (@tests) { given ($foo) { when ("abc") { say "$foo = exact match" } when (["foo", "bar"]) { say "$foo = list match" } default { say "$foo = no match" } } } say "*** Using nested ternary ***"; for my $foo (@tests) { say "$foo = ", ( $foo eq "abc" ? "exact" : grep($foo eq $_, ("foo", "bar")) ? "list" : "no" ), " match"; } ' *** Using given/when *** abc = exact match bar = list match def = no match foo = list match *** Using nested ternary *** abc = exact match bar = list match def = no match foo = list match
Update: s/-Mstrict -Mstrict/-Mstrict -Mwarnings/
-- Ken
In reply to Re: Smart matching is experimental/depreciated in 5.18 - recommendations?
by kcott
in thread Smart matching is experimental/depreciated in 5.18 - recommendations?
by coolmichael
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |