I've had similar experiences quite a while ago, just after having discovered Perl. Before then I'd mainly been playing around with C, so discovering there was a way to emulate Switch made me quite a happy camper. Initially it all worked fine, and then things just started going funky. Quite dazzled, I finally ended up replacing the entire Switch by a huge(and i do mean huge, a couple hundred possibilities) if-elsif-elsif-else contraption which worked exactly the way I wanted it to. Never really looked back after that. If something doesn't work exactly the way it is supposed to work, especially when there's a perfectly good alternative, why take the risk?

To stray from the topic for a moment, I can't think of a reason why it would be impossible to implement a form of switch in pure Perl though. It'd likely be a lot slower than if-elseif-else, but it'd make for a nice intellectual challenge ;-)

Obviously someone already rose to the challenge, as I could have predicted had I turned my brain up a notch for just a second there. Seems that someone also happened to post just before I did...

Remember rule one...

In reply to Re^3: question regarding using Switch.pm in production use by Forsaken
in thread question regarding using Switch.pm in production use by jfroebe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.