Dylan Storey

Recovering academic, hacker, tinkerer, scientist.

Switch statements in Perl

Switch statements in Perl.

I needed switch statements recently for perl and didn’t want to rely on the Switch module for portability reasons.

for ($var){
    if ('value') {$var = 2; last SWITCH;}
    if (/regex/) {$var = 1; last SWITCH;}
    if (1) {sub { print"yay";} ;last SWITCH;}
    if (2) {last SWITCH;}
    $var = 'default';
blog comments powered by Disqus