The problem is you are not looking for unique words in each file, but for unique words across all the files. Do I understand your requirement correctly?
#!/usr/bin/perl use warnings; use strict; my %seen; for my $file (@ARGV) { open my $FH, '<', $file or die $!; while (<$FH>) { chomp; s/,\s*$//; push @{ $seen{$_} }, $file; } } for my $string (grep 1 == @{ $seen{$_} }, keys %seen) { print "$string unique in $seen{$string}[0]\n"; }

$ perl 1077045.pl [123].txt cat unique in 1.txt dog unique in 3.txt rat unique in 2.txt

If the word is considered "unique" even if it occurs several times in one file, you might need to use a HoH instead of a HoA.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re: How can one get the unique words in text files using perl module List::Compare? by choroba
in thread How can one get the unique words in text files using perl module List::Compare? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.