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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.