The
eval is necessary if you want to fully emulate the C semantic of not dieing if there is no matching case. Really, the full-on computed goto method (I should have just written this into my top-level response) is this (I think):
{
eval { goto "CASE$var" } or goto DEFAULT;
CASE10: print "a";
CASE9: print "b";
CASE8: print "c";
CASE7: print "d";
CASE6: print "e";
CASE5: print "f";
CASE4: print "g";
CASE3: print "h";
CASE2: print "i";
CASE1: print "j";
DEFAULT:
}
Which, admittedly, is not very different from
Aristotle's. The only real difference being the outter braces. The purpose of them is to avoid polluting the label name-space. (Also, I prefer the "goto X or goto DEFAULT" over the "goto X; goto DEFAULT" purely for aesthetic reasons. :-D)
I sort of wonder why this isn't given as one of the ways of achieving C-like switch statement behavior in the perl docs? Oh, well... it's probably horribly inefficient or something (apart from just being too C-ish or something).
------------
:Wq
Not an editor command: Wq