Howdy :)

I have a piece of code that looks like this:

$send_flag = $bbstatus ne $last_bbstatus ? 1 : ($now - $last_send_time) > $min_frequency ? 1 : defined($OPTS::opts{f}) + ? 1 : + 0;
Basically, it just sets a flag (or not) if any one of multiple conditions are met. It seems to work fine as I have it, but I now find that I need to extend it so that a message is presented to the user, indicating which condition was met. I'm trying to avoid a series of if/elsif's, so my initial thought was to do something like:
$send_flag = $bbstatus ne $last_bbstatus ? 1 : ($now - $last_send_time) > $min_frequency ? 2 : defined($OPTS::opts{f}) + ? 3 : + 10;
And then....
my %send_messages = ( 1 => "Status has changed", 2 => "Last send too old", 3 => "Forced send requested", 10 => "No changes" );

However, the above seems a bit unsightly, and I'm wondering if this is a situation where a dispatch table would be appropriate? And if so, how would this be structured? (I don't have any experience with dispatch tables, and although I've read a few related threads here and here, I'm afraid I'm having trouble grasping exactly when they are appropriate and how they are constructed).

Appreciate any advice.

Thanks,
Darren :)


In reply to Is a Dispatch Table appropriate here? by McDarren

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.