in reply to How can one get the unique words in text files using perl module List::Compare?
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can one get the unique words in text files using perl module List::Compare?
by supriyoch_2008 (Monk) on Mar 05, 2014 at 11:10 UTC |