Not that you shouldn't try to find a faster or cleaner way to do this, but I'm of the opinion that correctness trumps speed. After you have a correct algorithm you usually can obtain faster speeds by parallelizing the task, and that's probably the best use of your time.

That said, here are some small improvements to your code that could result in better performance:

1) Use elsif where possible, i.e.:

if (/wire capacitance/) { ... } elsif (/wire resistance/) { ...
From your example file, it doesn't seem like you'll see both wire capacitance and wire resistance on the same line. Also, consider using elsif in the other chain of if statements if only one condition can be true at a time.

2) Use: if ($TotalNets % 50_000 == 0 && $TotalNets > 0) ... to test if you want to print out the trace message. It's simpler, cleaner and faster.


In reply to Re: Looking for ways to speed up the parsing of a file... by pc88mxer
in thread Looking for ways to speed up the parsing of a file... by fiddler42

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.