Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: improve ugly flow control

by Arunbear (Parson)
on Sep 19, 2004 at 14:40 UTC ( #392190=note: print w/replies, xml ) Need Help??


in reply to improve ugly flow control

my @Tests = ( { cond => sub {$_[0] eq 'blue'} , action => sub { print "$_[0] is good"} }, { cond => sub {$_[0] eq 'red'} , action => sub { print "$_[0] is bad"} }, { cond => sub {$_[0] eq 'green'} , action => sub { print "$_[0] is ugly"} }, ); OUTER: foreach my $try (@options) { foreach (@Tests) { if ($_->{cond}->($try)) { $_->{action}->($try); $_->{success}++; last OUTER; } } } log_failure() unless grep {exists $_->{success}} @Tests;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://392190]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2016-12-08 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (143 votes). Check out past polls.