use strict; use Data::Dumper; my $candidate = 'the the the the the the the'; my @candidate_words = split (/\W/, $candidate); my $candidate_count=@candidate_words; my %candidate = (); map { $candidate{$_}++ } @candidate_words; my $reference = 'the cat is the on the mat'; my @reference_words = split (/\W/, $reference); my %reference = (); map { $reference{$_}++ } @reference_words; while((my $key, my $val)=each(%candidate)){ print $key."->".$val."\n"; } print "-------------------------------------\n"; while((my $key, my $val)=each(%reference)){ print $key."->".$val."\n"; }
This scripts i m writing to find similarity between two sentences. The two sentences are stored in $candidate and $reference variables.
In the current script i made the program to count the occurence of each type of word and stored them in a hash.. Now,each hash has the words and its count from both candidate and reference sentences.
The help in need is, i want to take each words in the candidate and compare that with the two hashes to find the maximum reference count. for eg. if i have the word called "the" in candidate,i want to find the count of this word in %candidate hash as well as %reference hash and i want to take the minimum values(i.e if 2 and 5 is the count of "the" in two hashes i want 2.) out of this two counts. likewise for all words in the candidate.. Plz help me in this.. thanks
In reply to hash comparison by sarvan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |