This is a problem i have faced many times, and ended up writting some really odd code to reuse. But, most of the time, i found goto to be a fine solution. There will be people who will down vote this because the "dislike" goto, though i would guess they have never used it, and have only read that it is bad.
But, goto does require a moments thought. What i have done is something like the following (untested):
use Getopt::Long;
my $RECOV_STEP = 'FTP_FILE';
my $optre = &GetOptions("-restart=s" => \$RECOV_STEP);
if ($optre == 0) {
print "Invalid Option Processing\n";
&usage();
}
eval {
goto $RECOV_STEP;
};
if ($@) { die "Invalid Recovery Step '$RECOV_STEP'\n" };
FTP_FILE: {
### get data
print "FTP Step Started\n";
};
LOAD_FILE: {
### load database with file
print "Load Step Started\n";
};
CLEANUP: {
### archive data
print "Cleanup Step Started\n";
};
sub usage {
print "$0 -restart <STEP>\n";
}
I have worked with production operation groups for some time now, and have found that they seem to prefer named restart "steps" as opposed to numbers. <minirant>While this may be diffrent where you are, unless you want to be the person up as night on the phone telling them the numbers, i suggest named steps and a good document.</minirant>
my own worst enemy
-- MZSanford
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|