in reply to What is the most efficient perl switch/case statement?

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)

Replies are listed 'Best First'.
Re: Re: What is the most efficient perl switch/case statement?
by synistar (Pilgrim) on Nov 21, 2003 at 15:24 UTC

    Actually, I do use CGI::Application. And I have used hashes as dispatch tables before (actually reinvented that wheel myself after dipping my toe in some assembly code). I usually use switch type statements for combining regex tests and other kinds of comparisons/tests (like in the example). I was not aware of Tie::Hash::Regex however. That is something I will rtfm on. CPAN is so massive I find it hard to keep up with it all (and that is a good thing).

    UPDATE:Tie::RegexpHash also seems like a pertinent module to check out. It allows one to use regexes as hash keys.