in reply to improve ugly flow control
How about putting a "fail" sentinel at the end of @options and in %hash, such that do_something('fail') is the same as log_failure()? That way, your loop simplifies to:
Now admittedly, inserting the sentinel into @options and %hash is obnoxious and hackish, but better to have that in your data than in your code....foreach (@options) { if(exists $hash{$_}) { # always true for $_='fail' &do_something($_); last; } }
--
F
o
x
t
r
o
t
U
n
i
f
o
r
m
Found a typo in this node? /msg me
% man 3 strfry
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: improve ugly flow control
by Aristotle (Chancellor) on Sep 19, 2004 at 11:07 UTC |