# To find unique words in files: #!/usr/bin/perl use warnings; use List::Compare; # Module # To enter many files: my $entry; my @a; # Use of do-until loop: do {print"\n\n Press 1 to enter a new file or 2 to exit: \n"; # do LOOP $entry=; chomp ($entry); $file_no=0; if ($entry==1) {$file_no++; # if LOOP starts # Upload the files: print "\n Enter the filename: "; $file=; chomp $file; ############################ # open the file, or exit: ############################ unless ( open(FILE, $file) ) { print "Cannot open file \"$file\"\n\n"; exit;} @string = ; close FILE; $string=join(" ",@string); $string=~ s/\s//gi; push @all,$string; } # End of if LOOP } until ($entry==2); # End of do-until LOOP ############################################### ################################################ $fnum=0; $wnum=0; foreach $item (@all) {$fnum++; # 1st foreach LOOP for all files @file_words=(); # To empty array while ($item=~ /[A-Za-z].*?,/g) # While LOOP2 starts { $wnum++; $word=$&; $word=~ s/,//g; $word=~ s/\s//g; push @file_words,$word; } # while LOOP2 ends for all words in file $num_all_words=@file_words; print "\n File No. $fnum Total Words: $num_all_words Words are:\n"; print join ("\n",@file_words); print "\n\n\n"; push @s,\@file_words; } # foreach LOOP ends $ele_no=@s; print "\n\n Elements No.: $ele_no\n Final Array: @s\n\n"; $all=List::Compare->new(@s); # Use of module function @file1=$all->get_unique(0); @file2=$all->get_unique(1); @file3=$all->get_unique(2); print "\n\n Unique Words in Files:\n\n file1: @file1\n file2: @file2\n file3: @file3\n\n"; exit; ####################