Here is a way that will work, without using modules.
This design is limited to comparing 31 files (assuming a 32 bit machine). Yes - I could extend it to 32 files at the expense of even more obfu.
my @file1 = qw{1 2 3 4 };
my @file2 = qw{ 2 3 4 5};
my %seen;
my @fa =([1<<1,\@file1,'File-1 only'],[1<<2,\@file2,'File-2 only'],
[1<<1|1<<2,[],'Both have']);
for (@fa){
my ($v,$f)=@$_;
$seen{$_} |= $v for @$f
};
## print Dumper \%seen;
for (@fa){
my ($v,$f,$n)=@$_;
$v==$seen{$_} and print qq[$n :$_\n]
for sort keys %seen
}
Prints:
File-1 only :1
File-2 only :5
Both have :2
Both have :3
Both have :4
Update: Updated code to also print "Both" lines.
"Man cannot live by bread alone...
He'd better have some goat cheese and wine to go with it!"
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.