Keep It Simple, Stupid | |
PerlMonks |
Nested foreach problemby Anonymous Monk |
on Aug 19, 2008 at 16:52 UTC ( [id://705265]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am seeking help on a script using nested loops.
I am extracting a name from @name_array, and searching each line of each file in @files. If the line contains the name ($wanted_name), I want the line to be printed into OUTPUTFILE. Problem 1 : Don't know how to pass a variable $wanted_name into a regular expression. It must be a variable to be updated. Someting like: if ($line =~ m/$wanted_name/i) etc.. Problem 2: OK, since I can't deal with Problem 1, if I hard-code a name I know to exist in several files (and therefore will be printed to OUTPUTFILE), the matching lines will be printed but REPEATEDLY. It seems as if the program runs correctly, then repeats itself like there is some form of infinite loop going on. Thanks in Advance
Back to
Seekers of Perl Wisdom
|
|