Perl Monk, Perl Meditation | |
PerlMonks |
Re: Given When Syntaxby kcott (Archbishop) |
on Mar 16, 2014 at 00:19 UTC ( [id://1078496]=note: print w/replies, xml ) | Need Help?? |
G'day Deep_Plaid, I see you've already been advised about either: specifying a version (with use) which automatically loads the feature you want; or, specifying the feature by itself. For "switch", that's one of:
or
However, as you're using 5.18.1, you'll now get warnings about experimental features unless you also switch them off like this (as explained in "perl5180delta: New mechanism for experimental features"):
Furthermore, that's somewhat counter-intuitive because, if you used what you might think would be the correct way to to do this, i.e.
you'll get
What you actually need is:
Without this, you'll get a warning message for every given and when in your code, i.e. for the code you posted:
At this point, you may have decided not to use experimental features. They're certainly not a good idea in production code. Here's some additional information on both Switch and switch: "Re: switch statement". Finally, here's a version of your code which generates no errors or warnings (I used 5.18.1 — the same version as you're running). In addition, while I see you've been provided with many alternatives to given/when, here's two more. [Note: this is just example code that includes no argument checking.]
Output:
-- Ken
In Section
Seekers of Perl Wisdom
|
|