[sf-perl] a reason to goto

Joe Brenner doom at kzsu.stanford.edu
Sat Feb 24 01:54:14 PST 2007


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;
        }
      }
    };


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) )
    } 



More information about the SanFrancisco-pm mailing list