Thanks! I really appreciate the break down of improvements, trying to do better I just don't always understand the suggestions and as a bad habit sometimes I turn off strict until I get something working then go back and polish it, a lot room for improvement still.

If you have a moment I've run into a desire to join the script you helped with to another that's similar, I'm not following the logic of how to iterate over multiple sources very well. I'll repost what I'm using now for example. In the first script that you helped with it takes a value from $search file to see if its in the $schedule file that's read into a hash at the beginning, which is great thanks to your your help.

I have another function which was done separately because I generally find doing tasks in smaller chunks easier to understand and get right, but I'd like to bring them together, this one reads $schedule line by line, when it matches a regex pattern it pushes that value into an array, when it reaches the value from the $search_file, I have it print the last value stored in the array, because its not the $search_file value I need next, its actually a value several lines above it that I captured with regex so this is kind of a look behind procedure?

Basically my confusion hit turbulence trying to do both, does it make sense to then change the first script to iterate line by line instead before trying to pair them, or is there a way to still do the regex capture if I'm instead using the existing hash already saved in the first script?
use warnings; use strict; open my $schedule, '<', 'Schedule'; my %schedule; $schedule{$_} = 1 while (<$schedule>); close $schedule; open my $wave, '>', 'Wave' or die "Can't open 'Wave': $! +"; open my $keywords, '<', 'Agents' or die "Can't open 'Agents': +$!"; open my $search_file, '<', 'Definitions' or die "Can't open 'Definitio +ns': $!"; my $keyword_or = join '|', map {chomp; qr/\Q$_\E/} <$keywords>; my $regex = qr|\b($keyword_or)\b|; open my $schedule, '<', 'Schedule' or die "Can't open 'Schedule': $!"; while (defined (my $line = <$search_file>)) { while ($line =~ /$regex/g) { next if $line =~ /(SCRIPTNAME|DESCRIPTION)/; my $lineout = $line; chomp $lineout; print $wave $lineout; print $wave exists $schedule{$line} ? " | Yes \n" : " | No +\n"; print $wave exists $schedule{$line} ? " | Yes \n" : " | No +\n"; # at this point my output looks something like this: VALUE_FRO +M_SEARCH_FILE | Yes # want to use the value in $line as the input variable to the +other script where marked as $value_from_line_in_search_file # want to print the result of other script back here # at this point I would like the output like this: VALUE_FROM_ +SEARCH_FILE | Yes | VALUE_FROM_SCHEDULE_FILE last; } }
use warnings; use strict; my $value_from_line_in_search_file = 'SAMPLE#DATA'; open my $schedule, '<', 'Schedule' or die "Can't open 'Schedule': $!"; my @values=(); while (<$schedule>) { if (/(^SCHEDULE)(.*)/) { # SCHEDULE SCHEDULENAME, I only want the na +me. push(@values, $2); } if (/$value_from_line_in_search_file/) { print $values[-1]; last; } }

In reply to Re^2: nesting loops help? by shadowfox
in thread 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.