rr27:
Just a couple simple things:
into:if (cond) { ...stuff... } else { #nothing here if (cond2) { ...more stuff... } #nothing here, either }
if (cond1) { ...stuff... } elsif (cond2) { ...more stuff... }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |