in reply to Switch (module) and Apache::Registry problem.

Yeah, Switch is really cool. Don't use it.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Switch (module) and Apache::Registry problem.
by jdtoronto (Prior) on Oct 30, 2003 at 16:41 UTC
    Okay, so switch is too cool for its own good eh :)

    Thanks guys, now I can go back to my ugly old nested if's and not feel guilty! I always liked the switch/case construct in EBasic back in the CP/M - MP/M days, and then in C of course, always wanted one in Perl - I suppose I have to wait for Perl 6 for given/when.

    jdtoronto

      Not all is lost for Perl5. A hash containing subroutine refs can be equally readable, though fall-through can be difficult to achieve. It also has the advantage of having O(1) efficiency, just like switches in C (an interesting discussion of which is here).

      In C switches, you trade off some flexibility for efficiency. Perl6 switches will allow any expression to be used as a case, so they're basically as efficient as a bunch of if/elsif statements (though I'm hoping simple cases will be optimized into something like a C switch).

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated