Build a Hash of Arrays (HoA) (see perldsc) and check each element with grep
poj#!/usr/bin/perl use strict; use warnings; my $filecount = 25; my %count = (); my @files = map { "File $_.txt" }(1..$filecount); for my $i (0..$#files){ open IN,'<',$files[$i] or die "Could not open $files[$i] : $!"; while (<IN>){ chomp; $count{$_}[$i] += 1; } close IN; } my @result=(); print join "\t",'ID Name',@files,"\n"; for my $key (sort keys %count){ my @all = (); for my $i (0..$#files){ if (defined $count{$key}[$i]){ $all[$i] = $count{$key}[$i]; } else { $all[$i] = 0; } } print join "\t",$key,@all,"\n"; # debug # skip if any are zero next if grep( $_==0, @all ); push @result,$key; } print "\nCommon to all\n"; print "$_\n", for @result;
In reply to Re: find common data in multiple files
by poj
in thread find common data in multiple files
by mao9856
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |