Archive - Originally posted on "The Horse's Mouth" - 2006-12-17 10:13:10 - Graham Ellis
It has always struck me that switch statements in languages like C, PHP, Tcl and Java are very longwinded and clumsy, with a need for blocks and blocks, and every case having to end with a break (or equivalent) to stop multiple cases being run via a drop-through. I can understand why they were written that way in the first place but ... ouch.
Ruby's case / where, then, is a breath of fresh air. Easy block structure, multiple options allowed (and a special === test that helps make the case selection easy) and no need for those breaks either!
Larry Wall has steadfastly refused requests for a switch in Perl as you don't need it and ... he agrees with me ... it's clumsy. But Perl 6 will have a given alternative with when clauses which works in a similar way to the superb Ruby solution. My hat off to Matz and Larry.