Hello everyone!

I have run into a dilemma and I can't seem to find my way out.

I have a text file, and in that text file (somewhere) is a list of .txt files. These .txt files are listed in this text file because they were created in a directory due to some environmental variables.

I want to be able to take the text file names that were generated out of the text file, and compare it to a list of files in a directory and run searches against the files that come back with a positive match.

Here is the code I have for getting the list of files in a directory:

my $directory_path = undef; my @directory_path_file_list = undef; opendir DIR, $directory_path or die "Cannot open directory $directory_ +path"; @directory_path_file_list = readdir DIR; closedir DIR;
I then have the following code for getting the list of file names out of the text file:
my $text_file = undef; my @text_file_names = undef; $text_file = "text_file_with_names.txt"; open (my $fh, '<', $text_file) or die("Can't open input file \"$text_file\": $!\n"); while (my $line = <$fh>) { chomp $line; my @strings = $line =~ m/=(\s+\S+.txt)/x; foreach my $s (@strings) { @text_file_names = $1; } }

The way this works right now, is I am able to see the array of all the current files in the directory, and I can pull the name of the .txt file out of the second array one by one, but I don't know how to compare them to catch positive matches. I could be going at this the completely wrong way, which I am fully ready to accept!

Like I mentioned earlier in the post, I want to be able to compare the text file that contains the list of generated text file names and the current list of files in the directory path. Once they are compared I want to act upon the file name of the positive matches.

Please let me know if that doesn't make sense, I'm trying to explain it the best I can.

Thank you!


In reply to Gather List of Files from Text - Compare Against List of Files from Directory by Nico

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.