On the one hand, you may be right about this not even being a perl problem, but OTOH, encapsulating this problem into a perl script might be a simple, coherent way to keep track of what the process is really supposed to be (assuming you put some coherent commentary in the script).

If I understand the problem, you have a list of patterns to search for in a set of *.inp files. If you have that list stored in a file, with commas and whitespace as you have indicated, then the script starts by turning that list into a suitable regex pattern. Then it searches for the files where this regex pattern needs to be sought out. Then you'll do something wiht the list of files where the regex matched:

#!/usr/bin/perl use strict; # get the regex pattern my $regex; open( L, "that.list" ) or die "that.list: $!"; { local $/; $_ = <L>; s/^\s+//; # remove initial whitespace, if any s/[,\s]+$//; # remove final comma and whitespace s/\s*,\s*/\|/g; # convert internal separators to "|" s/\./\\./g; # escape period characters $regex = $_; } close L; # now look for candidate files # (I prefer using unix "find"...) my @found; open( F, "find . -name '*.inp' |" ) or die "find: $!"; while (<F>) { chomp; my $datafile = $_; if ( open( DATA, $datafile )) { local $/; $_ = <DATA>; push @found, $datafile if ( /\$open yields/ and /$regex/ ); close DATA; } else { warn "open failed on $datafile: $!\n"; } } # @found now contains the set of file names that are needed
Of course, the original list file (containing the patterns to search for) could be a command-line arg or piped in on this script's STDIN, in which case forget the "open(L,..." statement, and read the regex data with  $_ = <>;

(It might be good to state the actual path where the target files are supposed to be found, and put that path into the "find" command in the script, rather than assume that the CWD will be the correct one when the script runs.


In reply to Re: Parsing a list of files to see if any contain any one of a list of comma delimited strings by graff
in thread Parsing a list of files to see if any contain any one of a list of comma delimited strings by OfficeLinebacker

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.