Switch uses source filters, which are generally considered a poor and buggy solution. To quote from the perl 5.10.1 perldelta:
Switch is buggy and should be avoided. From perl 5.11.0 onwards, it is intended that any use of the core version of this module will emit a warning, and that the module will eventually be removed from the core (probably in perl 5.14.0). See Switch statements in the perlsyn manpage for its replacement.
| [reply] |
CheeseConQueso:
Primarily because it's a source filter: In other words, it rewrites your code before the parser can parse it. So it'll probably work perfectly nearly all of the time. But if it gets confused, the parser is going to report problems on the rewritten code, rather than the code you're working on. So the line numbers and/or descriptions of the errors may have little bearing on the source code you're working on. Additionally, if the module gets confused, it may alter code not related to any switches. This can be confusing, since you probably won't suspect Switch to be the cause of a problem where there are no switch statements near the reported problems.
...roboticus
| [reply] |
| [reply] |
I used the Switch module around 2006 in a program of a few thousands of lines that was supposed to be used in a production environment. It caused some surprising bugs. I don't even remember what they were exactly, but it really wasn't something that i would expect to come from using such a module. It didn't save me any typing and didn't add any elegance to the code, and i wasted some time (an hour maybe) trying to understand what causes the bugs until i just replaced it with if/else and didn't look back.
given/when is great if you can use it, though.
| [reply] |