Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Is a Dispatch Table appropriate here?

by Belgarion (Chaplain)
on Dec 14, 2005 at 05:38 UTC ( #516529=note: print w/replies, xml ) Need Help??

in reply to Is a Dispatch Table appropriate here?

Since your first line really wants a boolean, I would have changed your first line to something like:

$send_flag = ($bbstatus ne $last_bbstatus) or (($now - $last_send_time) > $min_frequency) or defined($OPTS::opts{f});

If you're really looking for a dispatch table you could do something like:

my @messages = ( [ sub { $bbstatus ne $last_bbstatus }, "Status not changed" ], [ sub { ($now - $last_send_time) > $min_frequency }, "Last send too +old" ], [ sub { defined($OPTS::optf{f}) }, "Forced send requested" ], [ sub { 1 }, "No changes" ], ); foreach my $m (@messages) { print $m->[1], last if $m->[0]->(); }

Note: the above is completely untested.

Update: I thought of another way of implementing this while in the shower. It does avoid the dispatch table, and it does set the correct variables based on the booleans. Still, it may not be easy to read for newer Perl developers.

my $send_message = ($bbstatus ne $last_bbstatus and "Status no changed") or (($now - $last_send_time) > $min_frequency and "Last send too o +ld") or (defined($OPTS::opts{f}) and "Forced send requested") or "No changes"; my $send_flag = $send_message ne "No changes";

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516529]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2023-03-21 08:30 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.