rr27:

Just a couple simple things:

Finally, your $xx_gate variables are all doing a similar task. You're basically doing a simple state-based parser where you're using the gate variables to track which section you happen to be in. If I were doing it, I'd use a single variable, and use text values to make the code a little easier to read. Additionally, since you're sitting in a loop and using mutually-exclusive if statements to do one small chunk each time through the loop, you can use the next statement to avoid some else statements. So where you have code something like:

while (<FILE>) { if ($ban_gate==1) { if ($_=~/END_BANNER/) { # found end of section, do stuff and turn off section process +ing $ban_gate=0; } else { # process a line in the banner section } } else { if ($ras_gate==1) { if ($_=~/END_xxxx/) { # found end of section, do stuff and turn off section proc +essing $ras_gate=0; } } else { # process a line in the ras section } } }

I'd write it more like:

while (<FILE>) { if ($state eq 'BANNER') { if ($_=~/END_BANNER/) { # found end of section, do stuff and turn off section process +ing $state='-none-'; next; } # process a line in the banner section } elsif ($state eq 'RAS') { if ($_=~/END_xxxx/) { # found end of section, do stuff and turn off section process +ing $state='-none-'; next; } # process a line in the ras section } }

...that's enough for now.

Note: while I strongly suggest using the first three items, the rest are more opinion and style and you should take them with a grain of salt.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Perl script speed by roboticus
in thread Perl script speed by rr27

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.