On running this script the first thing done - after standard parameter validation - is to see if the stepfile exists. If it does this is a re-run and whatever step number this file contains is where the script re-starts. This is the reason for a goto. I don't think that my program logic is flawed here as the goto is only to be used as part of this automatic re-start code and as such will only be used once.

Hmm ... how about something like a dispatch table keyed by order:

my %cmd_steps = ( 1 => "/bin/ls", 5 => "/bin/uname", 10 => "/bin/dmesg", 15 => "/bin/date", 20 => "/bin/hostname", 25 => "/bin/mount", 30 => "/usr/bin/dir", 35 => "/usr/bin/lpq", 40 => "/bin/ps", ); my $next_step = 15; foreach my $step ( sort { $a <=> $b } keys %cmd_steps ) { next unless $step >= $next_step; print "Step: $step - Cmd: $cmd_steps{ $step }\n"; my $out = `$cmd_steps{$step}`; print $out; print "="x80, "\n"; }

Sure if you have a huge number of steps you'll gain a few cycles using goto vice spinning over unused steps but hey ... tradeoffs.

-derby

In reply to Re: Go to? by derby
in thread Go to? by Ronnie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.