G'day symgryph,

"I have read a lot about NOT using the 'switch' statement of yore, ..."

You need to be a bit careful with terminology. Perl does not have nor, as far as I know, has ever had a 'switch' statement. It does have "The 'switch' feature". There is a CPAN Switch module which provides a 'switch' function. I'm going to assume that you're talking about the Switch module.

The BUGS and LIMITATIONS sections of Switch both provide a number of reasons to avoid it. I would strongly recommend against using it in production code.

"... but saw some comments on using 'when' instead."

I'll assume that's from the Switch BUGS section: "In general, use given/when instead.".

When that was written, it was probably an entirely reasonable statement; however, in 5.18.0 'given', 'when, and the associated '~~' operator, were made experimental: "perl5180delta: The smartmatch family of features are now experimental". At 5.34.0 they remain experimental:

$ perl -v | head -2 | tail -1 This is perl 5, version 34, subversion 0 (v5.34.0) built for cygwin-th +read-multi $ perl -E 'say 1~~2 ? "yes" : "no"' Smartmatch is experimental at -e line 1. no $ perl -E 'my $x = 1; given ($x) { when (2) { say "yes" } default { sa +y "no" } }' given is experimental at -e line 1. when is experimental at -e line 1. no

Again, I would not use these in production code.

"Is there a modern howto on doing a case like construct in perl 5.34?"

— Ken


In reply to Re: Modern exposition of "case" or Switch in perl 5.34? by kcott
in thread Modern exposition of "case" or Switch in perl 5.34? by symgryph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.