Is there anyway to use the first REGEX match to generate the second REGEX statement?

Yes, there is, and I see you're already doing this in your regular expression /($pkt) (\w+) = (\d+)/. If, for example, $pkt is "abc.def", the pattern will be the equivalent of /(abc.def) (\w+) = (\d+)/. If you don't want the dot and any other characters to be interpreted as special regex characters, you can write your regex as /(\Q$pkt\E) (\w+) = (\d+)/, and the previous example regex becomes /(abc\.def) (\w+) = (\d+)/ (see quotemeta).

If this isn't working, after a first glance I will venture a guess as to why: your inner while loop is matching against $line_in instead of the current line from DAT_FILE, is that correct? If you want to match against the current line from DAT_FILE, it's enough to change that line to if (/($pkt) (\w+) = (\d+)/) {

If that's not the problem, it would help if you could provide more information on your question: some sample input, the desired program output, any error messages you might be getting, and a description of what the program is supposed to be doing and how that's different from what it's actually doing.

As you said there are other ways your code could be cleaned up (for example, it looks like you're opening and closing the file "$2_tlmval.txt" as OUT_FILE twice in a row, when you could just keep the file open), but first things first :-)


In reply to Re: How to use REGEX Match Variable from one 'While' String in Another 'While' String by Anonymous Monk
in thread How to use REGEX Match Variable from one 'While' String in Another 'While' String by GoldfishOfDoom

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.