madbombX,
It has already been pointed out that the number of conditions you need to account for are small enough that you can use a hash. Notice I didn't say dispatch table. This is because no code need be dispatched.
my $rv = $lookup{$outcome};
In other situations, it is resource prohibitive to store every possible condition ($outcome in your example) in the hash though the number of end states ($rv in your example) is quite manageable. In these situations I like to combine a smart search routine with a dispatch table:
$dispatch->{bin_search($outcome)}->();
In this particular case I have implied a binary search but it could be sequential as you have shown if that scenario fits your data. The point is you abstract finding the item in a list as well as what action to take upon the result.

Cheers - L~R


In reply to Re: Efficiency & Maintenance: if/elsif or Other Dispatch Method by Limbic~Region
in thread Efficiency & Maintenance: if/elsif or Other Dispatch Method by madbombX

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.