switch case is deprecated in Perl 5. If you are wondering why it got deprecated, here is the answer:
Switch case may create syntax errors in other parts of code. On perl 5.10.x may cause syntax error if “case” is present inside heredoc. In general, use given/when instead. It were introduced in perl 5.10.0. Perl 5.10.0 was released in 2007. Source.
However three new keywords: given, when and default got introduced in Perl 5 that provides functionality similar to switch case. This is how it looks:
given (argument) { when (condition) { statement(s); } when (condition) { statement(s); } when (condition) { statement(s); } . . . default { statement(s); } }
Read more about given-when-default here with example.
Leave a Reply