in reply to How to use REGEX Match Variable from one 'While' String in Another 'While' String
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 :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to use REGEX Match Variable from one 'While' String in Another 'While' String
by GoldfishOfDoom (Initiate) on May 07, 2014 at 18:40 UTC | |
by Anonymous Monk on May 07, 2014 at 22:39 UTC |