1

Have a quick question:

I want to use one/either of the following scripts to determine the common lines between all the combinations of different files in a directory (the directory has 25 files).

$ perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/'  file1 file2

or

$ comm file1 file2

However, I want to use the command on all of the possible bi-combinations of files (in my case that would be 300 unique file combinations).

Is there a way to modify this command line script to account for all possible combinations at the same time?

Thanks in advance for any help.

4

1 回答 1

4

有一个 CPAN 模块可以有效地生成组合:Algorithm::Combinatorics

use strict;
use warnings;
use Algorithm::Combinatorics qw(combinations); 

my @files = `ls <DIRECTORY>`;
my $iterator = combinations(\@files, 2);

while ( my $comb = $iterator->next ) {
   my ($file1, $file2) = @$comb;
   // call comparison script here
}  

可能有比您尝试做的更好的方法来解决这个问题,但这可以解决您的问题。

于 2013-10-28T18:46:53.320 回答