Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 romping around the Monastery: (6)
As of 2014-10-02 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (47 votes), past polls