[sf-perl] a reason to goto

Quinn Weaver quinn at fairpath.com
Sat Feb 24 09:07:33 PST 2007


On Sat, Feb 24, 2007 at 01:54:14AM -0800, Joe Brenner wrote:
> 
> I found a reason to use a goto!
> 
>   if ($RANDOMIZE) { 
>     DO_OVER: do { 
>       $i = pick_numeric(0, $numb_cards-1);
>       $j = pick_numeric(0, $numb_cards-1);
>       unless( $REFLEXIVE ) { 
>         if ($i == $j) { 
>           goto DO_OVER;
>         }
>       }
>     };

Hmmn!

> My first thought was to just say "redo", but that's a runtime 
> error: you can't use redo outside of a loop.  Not even inside a 
> "do" block... which I think counts as another perl oddity.
> 
> Of course, this could be re-written something like this, but I 
> wouldn't call it an improvement:
> 
>   if ($RANDOMIZE) { 
>     do { 
>       $i = pick_numeric(0, $numb_cards-1);
>       $j = pick_numeric(0, $numb_cards-1);
>       } until ( not( $REFLEXIVE ) && ($i != $j) )
>     } 

Furthermore, wouldn't this cause an infinite loop if $REFLEXIVE is true?

-- 
Quinn Weaver, independent contractor  |  President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/     |  http://sf.pm.org/


More information about the SanFrancisco-pm mailing list