http://qs1969.pair.com?node_id=912994


in reply to Re: Comparison between keys in hash
in thread Comparison between keys in hash

Hi i5513,

What i meant in the last statement is. I want to compare the keys at two hashes. let me be specific.

The whole program splits a sentence and compares each words of the sentence with two sentence i.e($str1,$str2).

What i needed is: for eg. if "the" word occurs in $str1 two times and $str2 one time. i want find the minimum value i.e is 1.

Same procedure for all the words in the sentence. The end output should give me the Word string and Its minimum count(after comparing counts in $str1 & $str2)..

Replies are listed 'Best First'.
Re^3: Comparison between keys in hash
by i5513 (Pilgrim) on Jul 06, 2011 at 16:40 UTC

    Then I would change your hash to:

    $counting{word}{$word}{str1}=$counter; $counting{word}{$word}{str2}=$counter;

    And then (see here for min function examples):

    foreach my $word (keys %{$counting{word}}) { print "$word\t", min ($counting{word}{$word}{str1}, $counting{word}{$word}{str2}) }
      hi i5513,

      Thanks for the code.. And in the context of my whole program,and ur changes in hash implementation, Is that $counter is same as $t1. because in my hash i store keys as ($occurence) and values as $t1.

      And also if possible can u put this in the code of mine. Sorry, i m really weak in perl.. that's why coundn't understand. Plz dont mind.

        Sorry but like others told you , we won't make your homework.
        RTFM and play with your code until you got the result.

        PD: Please tell me if pointer to RTFM is not a proper way to use perlmonnks ... I supersearched it and appears many entries, so I think it is ok ...
Re^3: Comparison between keys in hash
by jdporter (Chancellor) on Jul 06, 2011 at 15:09 UTC

    Sounds like homework.

Re^3: Comparison between keys in hash
by Anonymous Monk on Jul 06, 2011 at 15:16 UTC