Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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?
[choroba]: Yesterday, I gave Ramirez a headshot through the gate in Aztec. LOL. What happened to you? WTF? Sun. There was a hole in the window foil.
[LanX]: headshot ?
LanX s English not humorous enough

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-10-18 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (245 votes). Check out past polls.

    Notices?