Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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;


Comment on Re: improve ugly flow control
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-09-19 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (137 votes), past polls