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!"
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.