Perhaps something like the following?

First, I mocked up your input file as you didn't give an example:

= a.txt = c.txt = b.txt = e.txt

Here's the example code. Note I've changed your directory handle to a lexical one as opposed to a bareword global. Comments inline:

use warnings; use strict; my $directory_path = '.'; opendir my $dir, $directory_path or die "Cannot open directory $direct +ory_path"; # create a hash with the files in the dir # (makes lookup faster later on) my %directory_path_file_list = map { $_ => 1 } readdir $dir; closedir $dir; my $text_file = "text_file_with_names.txt"; open (my $fh, '<', $text_file) or die("Can't open input file \"$text_file\": $!\n"); # define a new array for the files listed in the file, # extract the names, and push each filename onto the new # array my @files_in_file; while (my $line = <$fh>) { if ($line =~ /=\s+(\w+\.txt)/){ push @files_in_file, $1; } } # loop over the files found in the file, then check to see # if each one exists in the hash we created earlier. # you can perform your actions inside of the 'if' statement for (@files_in_file){ if (defined $directory_path_file_list{$_}){ print "$_ file exists on disk\n"; } else { print "$_ file doesn't seem to exist\n"; } }

Update: It slipped my mind to use -e as Eily suggested, but that's the way I'd go as well.


In reply to Re: Gather List of Files from Text - Compare Against List of Files from Directory by stevieb
in thread 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.