|We don't bite newbies here... much|
Re: improve ugly flow controlby Zaxo (Archbishop)
|on Sep 19, 2004 at 07:41 UTC||Need Help??|
Last Update: This is wrong. See below for details.
Here's a somewhat exotic construction that I think reads well. Assumes that do_something() returns true on success.
or maybe better,
Untested, but I think it's nearly right.
The flipflop is true for zero or one keys and the initiating condition is not evaluated again after it is first true.
Update: Tested now, and it's not right. Trying to fix it.
Another Update: Is this a bug in perl's flipflop op? In perl-5.8.4
I'm using a variable $s there because bart++ tells me that flipflop can play games with $. if bare integers are presented to it.
Final Update: There is no bug, except in my logic. Changing the right hand side of the flipflop to match anything (//) instead of fooling with constants, I find by printing the sequence numbers that the flipflop switches off ok, but switches on again next time around.
Silly mistake on my part.
Here is a version that works, but it still needs that pesky $success variable I was trying to get rid of.
$success must be checked first to short-circuit the rest of the processing.