in reply to how to check if a particular value exist in list of files stored in an array
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to check if a particular value exist in list of files stored in an array
by Limbic~Region (Chancellor) on Oct 29, 2013 at 11:57 UTC | |
by hdb (Monsignor) on Oct 29, 2013 at 12:12 UTC | |
by Perlseeker_1 (Acolyte) on Oct 30, 2013 at 05:10 UTC | |
by hdb (Monsignor) on Oct 30, 2013 at 07:12 UTC | |
by Perlseeker_1 (Acolyte) on Oct 30, 2013 at 08:54 UTC | |
|