#!/usr/local/bin/perl -w use strict ; my $stopfile = 'stopwords'; my $base= shift @ARGV; # read in stopwords open STOP, "<$stopfile" or die $!; chomp( my @stop= ); close STOP; my %stopwords=(); # add the empty string '' to the stopwords as well @stopwords{@stop,''} = (); # read in basefile my %base_filterwords=(); open BASETEXT, "<$base" or die $!; while ( ) { @base_filterwords{ map { my $l = lc; exists $stopwords{$l}?():$l } split /\W+/ } = (); } close BASETEXT; # read in other files my %other_filterwords=(); while ( <> ) { @other_filterwords{ map { my $l = lc; exists $stopwords{$l}?():$l } split /\W+/ } = (); } continue { if (eof) { my $total = scalar keys %other_filterwords; my $intersect = 0; for my $key (keys %other_filterwords) { $intersect++ if exists $base_filterwords{$key}; } my $sim = 2*$intersect/$total; print "Similarity between $base and $ARGV = $sim\n"; print "\t@{[keys %other_filterwords]}\n"; print "\t@{[keys %base_filterwords]}\n"; # reset other filter words %other_filterwords = (); } }