Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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.


Comment on Re^2: Using dynamic operators in an if() statement
Download Code

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 contemplating the Monastery: (7)
As of 2014-10-31 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls