Nico has asked for the wisdom of the Perl Monks concerning the following question:
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:
I then have the following code for getting the list of file names out of the text file: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;
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Gather List of Files from Text - Compare Against List of Files from Directory
by Eily (Monsignor) on Mar 01, 2016 at 17:31 UTC | |
by Nico (Novice) on Mar 01, 2016 at 19:40 UTC | |
|
Re: Gather List of Files from Text - Compare Against List of Files from Directory
by stevieb (Canon) on Mar 01, 2016 at 17:51 UTC |