in reply to Extracting common keys present in multiple files
Then you need to extract the names - first get the names that appear at least 25 times in the %n_count hash, then, for each of those candidate names, get the ones that appear in all files.my (%f_count,%n_count); for my $file (@files) { open( my $fh, '<', $file ) or die "Couldn't read '$file': $!"; while (my $line = <$fh>) { chomp $line; next unless $line; my ($name,$number) = split(',',$line); $n_count{$name}++; $f_count{$name}{$file}++; } }
The only tricky bit here is the scalar keys %{ $f_count{$name} }my $num_of_files = scalar @files; my $min = 25; my @candidates = grep { $n_count{$_} >= $min } keys %n_count; for my $name (@candidates) { my $in_files = scalar keys %{ $f_count{$name} }; next unless $in_files == $num_of_files; print "$name\n"; }
|
|---|