in reply to Switch/case (given/when) in Perl5
Occasionally, people lament that Perl has no switch/case statement like C. Perl6 has given/when, which goes several steps beyond the simple switch by handling arbitrary conditions, rather than simple equivalence.One drawback of Perl6's given/when over a "simple" switch is that given/when is just a glorified if/else chain. Perl will have to check each clause in order to find a matching one. Years ago, I programmed in a language (some kind of Pascal/C bastard) where constructs like:
were optimized to do a binary search instead of a linear search. Of course, you can only do that if you only have constants in your cases, but I found it pretty neat.switch (... EXPRESSION ...) { case CONST1: ....; case CONST2, CONST3: ....; case CONST4 .. CONST5: ....; /* Range! */ case CONST6: ....; default; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Switch/case (given/when) in Perl5
by TimToady (Parson) on Mar 24, 2005 at 05:30 UTC | |
by Anonymous Monk on Mar 24, 2005 at 09:48 UTC | |
by TimToady (Parson) on Mar 24, 2005 at 16:43 UTC |