in reply to On goto
Trivially eliminating the goto, I'd go with:
Next, I hate the artificial $found variable, so I'd merely move that into a subroutine:{ ask('databasetype','Database type?','mysql'); my $found; # aside: I hate " = undef" foreach $cur (@databases) { if (getConf('databasetype') eq $cur) { $found = 1; last; } } unless ($found) { output "Sorry, invalid option\n\n"; redo; } }
That'd probably be enough, but that call to getConf seems to be perhaps invariant in that loop, so I'd pull it out to call the subroutine only once during the scan of @databases.{ ask('databasetype','Database type?','mysql'); unless (is_databasetype_valid()) { output "Sorry, invalid option\n\n"; redo; } } sub is_databasetype_valid { foreach my $cur (@databases) { if (getConf('databasetype') eq $cur) { return 1; } } return 0; }
But hopefully, you get the idea now.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: On goto
by Aristotle (Chancellor) on Mar 01, 2003 at 13:11 UTC | |
by merlyn (Sage) on Mar 01, 2003 at 15:48 UTC | |
by Aristotle (Chancellor) on Mar 01, 2003 at 16:04 UTC | |
Re: •Re: On goto
by zachlipton (Beadle) on Mar 01, 2003 at 02:02 UTC | |
by merlyn (Sage) on Mar 01, 2003 at 02:05 UTC | |
by djantzen (Priest) on Mar 01, 2003 at 06:23 UTC | |
by merlyn (Sage) on Mar 01, 2003 at 06:32 UTC | |
by Anonymous Monk on Mar 01, 2003 at 16:04 UTC |
In Section
Seekers of Perl Wisdom