|
|
| No such thing as a small change | |
| PerlMonks |
Perl 5.10 given/when tricks and caveatsby mr_mischief (Prior) |
| on Sep 04, 2008 at 21:08 UTC ( #709120=perlmeditation: print w/ replies, xml ) | Need Help?? |
|
In perlsyn you can find the words 'You can use the "continue" keyword to fall through from one case to the next'. You can also find this example:
Now, I'm not primarily a C programmer, but what I took "fall through" to mean is not what happens there. The "continue" doesn't skip the implicit break in the case, but means to actually continue testing cases.
That means this Perl code:
which prints: is not equivalent to this C code: which prints:
However, it means you can do neat tricks like this: which prints: So don't forget that you'll have to give up a little bit of convenience you might be used to with straight fall through. Happily, though, you end up with a good deal more convenience by being able to restart the switch and having the smart match applied again to the remaining cases. Unfortunately, this feature of continuing through the tests and having a default in the same switch statement are not really that smart a combination. Try giving that example from perlsyn the value x for $foo, and you get: ... which makes very little sense.
Back to
Meditations
|
|
||||||||||||||||||||||||||||||