I have a piece of code that looks like this:
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 ? 1 : defined($OPTS::opts{f}) + ? 1 : + 0;
And then....$send_flag = $bbstatus ne $last_bbstatus ? 1 : ($now - $last_send_time) > $min_frequency ? 2 : defined($OPTS::opts{f}) + ? 3 : + 10;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |