Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Using dynamic operators in an if() statement

by VSarkiss (Monsignor)
on Aug 22, 2006 at 15:06 UTC ( #568878=note: print w/ replies, xml ) Need Help??


in reply to Re: Using dynamic operators in an if() statement
in thread Using dynamic operators in an if() statement

Yes, this is a very good approach. To expand on it, you could even dispatch to multiple selection functions based on other criteria (the OP doesn't make clear what the criteria are, but hints at them). Something like this (untested) example:

my %match = ( high => sub { $_[0] > 98.0 }, low => sub { $_[0] < 55.0 }, exact => sub { $_[0] = 77.0 }, ); # ...later... my $test = decide_somehow(); if ($match{$test}->($consumption)) { print "Test $test succeeded\n"; do_something(); };
There are other ways to generalize the approach; this is just an example that may or may not be appropriate, depending on other program constraints.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2016-07-27 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (242 votes). Check out past polls.