in reply to Re: nesting loops help?
in thread nesting loops help?
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: nesting loops help?
by GrandFather (Saint) on Mar 10, 2022 at 20:52 UTC | |
by shadowfox (Beadle) on Mar 11, 2022 at 15:01 UTC | |
by GrandFather (Saint) on Mar 13, 2022 at 23:01 UTC | |
by shadowfox (Beadle) on Mar 14, 2022 at 02:52 UTC | |
by shadowfox (Beadle) on Mar 14, 2022 at 15:25 UTC | |
by GrandFather (Saint) on Mar 14, 2022 at 20:56 UTC | |
|