in reply to Re: GOTO or not GOTO
in thread GOTO or not GOTO
Lets restructure that code just a little:
use strict; use warnings; my @array = (\&blue, \&foobar, \&no); do { eval {$_->() for @array}; } while $@; sub quit { print "Would you like to do that again? 'y' or 'n'\n"; die if <STDIN> =~ /y/; print "OK, done.\n"; exit; } sub blue { print "Type 'blue' to continue:\n"; return 1 if <STDIN> =~ /blue/i; quit(); } sub foobar { print "Cross your fingers and type 'foobar' to continue:\n"; return 1 if <STDIN> =~ /foobar/i; quit(); } sub no { print "To quit (prematurely), type 'no'\n"; exit if <STDIN> =~ /no/i; die; }
Shorter, cleaner, no gotos and, IMO, clearer. Now, why did we need those gotos again?
|
|---|