<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w

use strict;
use warnings;
use 5.010;

my $size = scalar @ARGV;
if ($size &lt; 2) {
    die "The comparison is impossible, a minimum of two files to compare is required!\nPlease provide an acceptable number of files!\n";
}

print "Please specify an output file:\n";
chomp (my $outfile = &lt;STDIN&gt;);
open(OUTFILE, "&gt;$outfile") or die "Could not open $outfile: $!\n"; $_="1";

print "Please specify a file name if you request the list of compared item to be outputed in this file, otherwise state no:\n";
chomp (my $list_requested = &lt;STDIN&gt;);

my $scalar;
my $compare;

foreach my $arg (@ARGV) {
    ($scalar, $compare) = &amp;process_file ($arg);
}

my %scalar = %{$scalar};
my %compare = %{$compare};

print "\nThe comparison was performed on $size files!\n";

unless ($list_requested eq "no") {
    open(OVERLAP_LIST, "&gt;$list_requested") or die "Could not open $list_requested: $!\n"; $_="1";
    print OVERLAP_LIST "Compared items\tFlag\tFiles\n";
    foreach my $key (sort keys %compare) {
        print OVERLAP_LIST "$key\t$compare{$key}{flag}\t$compare{$key}{flag_code}\n";
        $key = ();
    }
    close (OVERLAP_LIST);
}

my %compare_bis;
foreach my $keys (sort keys %compare) {
    $compare_bis{$keys} = $compare{$keys}{flag};
}

foreach my $key (values %compare_bis) {
    $scalar{$key}{count}++;
}

print OUTFILE "Flag\tFlag code\tCount\n";
foreach my $keys (sort {$a &lt;=&gt; $b} keys %scalar) {
    print OUTFILE "$keys\t$scalar{$keys}{flag_code}\t$scalar{$keys}{count}\n";
}
close (OUTFILE);

print "\nNOTE TO USER: your files must not have headers and no duplicate values, and must consist of a single column!\nIf this is not the case modify your files in accordance or use another perl script!\n";

###############
# Sub-routine #
###############

sub process_file {
    my $file = $_[0];
    open(FILE,"&lt;$file") or die "Could not open $file: $!\n"; $_="1";
    my @file = &lt;FILE&gt;;
    close (FILE);
    state $i = -1;
    $i += 1;
    my $score = 2**$i;
    state %scalar;
    state %compare;
    $scalar{-$score}{flag_code} = "Total $file";
    $scalar{-$score}{count} = scalar @file;
    foreach my $entry (@file) {
        chomp($entry);
        unless (exists $compare{$entry}) {
            $compare{$entry}{flag} = $score;
            $compare{$entry}{flag_code} = "$file";
        }
        else {
            $compare{$entry}{flag} += $score;
            $compare{$entry}{flag_code} = join (", ", $compare{$entry}{flag_code}, $file);
        }
        my $flag = $compare{$entry}{flag};
        my $flag_code = $compare{$entry}{flag_code};
        unless (exists $scalar{$flag}) {
            $scalar{$flag}{flag_code} = $flag_code;
            $scalar{$flag}{count} = 0;
        }
    }
    return (\%scalar, \%compare);
}

__END__</pre></body></html>