develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-{Pre-RFC} - match/case syntax

Thread Previous | Thread Next
From:
Darren Duncan
Date:
June 27, 2022 09:11
Subject:
Re: Pre-{Pre-RFC} - match/case syntax
Message ID:
de7f58a3-faa5-45d8-a76e-b61c557c1a3b@darrenduncan.net
On 2022-06-24 3:17 p.m., Paul "LeoNerd" Evans wrote:
>    my $n = ...;
> 
>    match($n : ==) {
>       case(1) { say "It's one" }
>       case(2) { say "It's two" }
>       case(3) { say "It's three" }
>       case(4), case(5)
>               { say "It's four or five" }
>       default { say "It's something else" }
>    }

I consider that the best part of this is you specify inline the exact comparison 
operator or sub to use, the "==" in this case, meaning that the semantics of the 
matching is completely explicit, rather than some implicit complicated logic.

This should be generic and configurable in the same way map/grep/sort etc are.

-- Darren Duncan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About