in reply to if or switch?

I'm curious about why you rejected switch as an option - it seem to be exactly what you need.

You could even opt for the Perl6 style ..

use Switch 'Perl6'; given ($mystring) { when /key1/ { handle_Key1(); } when /key2/ { handle_Key2(); } when /key3/ { handle_Key3(); } default { handle anything else; } }

     Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Replies are listed 'Best First'.
Re^2: if or switch?
by chromatic (Archbishop) on Jul 11, 2008 at 06:17 UTC
    I'm curious about why you rejected switch as an option...

    Its own documentation suggests that it can fail with mysterious errors.

      chromatic - are you red flagging (or yellow-flagging) the use of the switch statement ?

      If so, could you specify which version you had bad experience with ?

      • Switch Module? V5 or V6 option ?
      • Perl6 (Rakudo, or pugs)?
      • Perl 5.10 "feature" module ?
      • Perl5 FAQ that fakes out "case" ?
      Was this an esoteric case ?

      Your response could help the community either toward reproducing and fixing bugs, or by directing programming practices based on your recommendation.

           Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

        See the documentation for the core Switch module. given/when in Perl 5.10 is more robust, and Perl 6 works effectively.

        The failure case isn't too esoteric; the use of regular expressions in your code can confuse Switch.