I have a working script that I need to update to cross reference another file, I'm clearly in the wrong headspace because I don't see my error.

First my working code is below, I'm basically opening 2 files for reading and 1 file for output, the $keywords file is opened and compared to the $search_file, if the line from the $keywords file is found in the $search_file I print that line from the $search_file into the $wave file. Pretty basic, their also a regex comparison to ignore certain lines I don't need. This works, runs in a second or two.

<new requirement>I now need to open yet another file, lets open it as $schedule. I need to see if the line I found in the $search_file is also in the $schedule file, if so, I want to print "yes" on the same line that I was printing into the $wave file while its on that step in the iteration. It seems pretty straight forward, but I've tried a few different ways to no avail, It ends up in a very long running loop that I eventually cancel, it's clearly not what I'm trying to do.

Does this make sense? I generally try to avoid nesting loops very deep and I'm clearly getting something wrong. Again the code below works for my previous need, I just want to add to it to add the <new requirement>
#!usr/bin/perl use warnings; open my $wave, '>', 'Wave' or die "Can't open $wave: $!"; open my $keywords, '<', 'Agents' or die "Can't open keywords: $!"; open my $search_file, '<', 'Definitions' or die "Can't open search f +ile: $!"; my $keyword_or = join '|', map {chomp;qr/\Q$_\E/} <$keywords>; my $regex = qr|\b($keyword_or)\b|; while (<$search_file>) { while (/$regex/g) { $line = $_; if ( $line =~ /(SCRIPTNAME|DESCRIPTION)/ ) { next; } print $wave $line; } } $_->close for $wave, $keywords, $search_file;
I'll keep working on it but I appreciate any insight you can provide

In reply to nesting loops help? by shadowfox

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.