This doesn't answer your question, but i'd rather use a dispatch table (a lookup hash) instead of Switch ... but i rarely care about premature optimization. In your case, you are also checking regexes, so i would probably use Tie::Hash::Regex like so:
use strict; use warnings; use Tie::Hash::Regex; tie my %hash, 'Tie::Hash::Regex'; %hash = ( 'foo.txt' => 1, 'bar.html' => 2, '..' => undef, '.' => undef, DEFAULT => undef, ); my $arg = shift || 'DEFAULT'; my $candidate = $hash{$arg}; die "invalid arg\n" unless $candidate; print "$candidate\n";
Since most of my work is Web based, i care more about maintainability and readability than efficiency .. but i do care about efficiency when it really matters.

UPDATE:
I forgot to mention CGI::Application which uses a dispatch table to control which runmode your CGI is in. If you haven't seen it yet, you really should RTFM on CGI::App ...

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: What is the most efficient perl switch/case statement? by jeffa
in thread What is the most efficient perl switch/case statement? by synistar

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.