XP is just a number | |
PerlMonks |
Re: Modern exposition of "case" or Switch in perl 5.34?by kcott (Archbishop) |
on Jul 03, 2021 at 01:58 UTC ( [id://11134610]=note: print w/replies, xml ) | Need Help?? |
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:
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 Section
Seekers of Perl Wisdom
|
|