in reply to hash comparison

If you want minimum, just replace the last while loop with this:
for my $key (keys %candidate) { print "$key -> "; my $cand = $candidate{$key}; my $ref = $reference{$key}; if ($ref and $ref < $cand) { print $ref; } else { print $cand; } print "\n"; }
For maximum, invert the < sign.

Replies are listed 'Best First'.
Re^2: hash comparison
by sarvan (Sexton) on Jul 25, 2011 at 07:47 UTC
    Hi, Thanks for the reply

    And here is the doubt. suppose a word in the candidate that is not at all present in the reference, in such case it gives me the count as 1.(since 1 time it appeared in $cand). But, i expect it to be zero. because it dint appear in $ref..

    An Example sentences: $candidate="it is not probable that it is the end"; $reference="it is unlikely that it is the end";

      It is trivial to change the code I provided to give the expected result (in fact, you did not specify what to do if the term does not occur in the $reference, so I assumed you wanted to see the value from $candidate). Just remove 9 characters and add 5 somewhere :) (YMMW)