Your approach is one good way to do it if you do a few minor modifications. Read your first file into a hash instead of an array for easier lookup:
my %records; open my $fh, "<", $file1; /^(\S+)\s/ and $records{$1}=1 while <$fh>; close $fh;
I am using a regular expression to find the first column in your file which seems to be simpler here and can also be used as a test. For example, empty lines will be skipped automatically this way.
Then open each of your other files in turn and check whether a given line shall be printed by doing a lookup in the hash:
for my $file (@filelist) { open my $fh01, "<", $file; /^(\S+)\s/ and defined $records{$1} and print while <$fh01>; close $fh01; }
I have skipped all checks whether files can be opened etc. You need to add those yourself.
In reply to Re: how to check if a particular value exist in list of files stored in an array
by hdb
in thread how to check if a particular value exist in list of files stored in an array
by Perlseeker_1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |