Hi everyone,

The below is my script.

#! /usr/bin/perl $str1='It is a guide to action which ensures that the military always +obey the commands of the party.'; chomp($str1); $str2='It is a guide to action that ensures that the military will for +ever heed Party commands is a guide.'; chomp($str2); @arr1=split(/\s+/, $str1); $n=0; %result=(); %output=(); for($i=0; $i<$#arr1;$i++) { $t1="$arr1[$i] $arr1[$i+1] $arr1[$i+2]"; @pattern_word_count=split(/\s/, $t1); $space_count=@pattern_word_count; if($space_count == 3) { if($str2=~/$t1/) { $occurence=`echo $str2 | grep -o '$t1' |wc -l` +; chomp($occurence); $result{$occurence}=$t1; print $i+1,"\t\t",$occurence,"\t\t\t$t1\n"; $n++; } if($str1=~/$t1/) { $occurence1=`echo $str1 | grep -o '$t1' |wc -l +`; chomp($occurence1); $output{$occurence1}=$t1; print $i+1,"\t\t",$occurence1,"\t\t\t$t1\n"; } } } print "\n\nTotal Matches : $n\n";

In this code, i am just comparing $t1 with $str1,$str2 and counting the no.of times it appears.. Then, i store the no.of occurence in two seperate hashes..(%result,%output)

My question now is, i want to compare the keys of first hash with the keys of 2nd hash and find the which has minimum value. This comparison has to be done for all the keys in both hashes.. Any suggestions


In reply to Comparison between keys in hash by sarvan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.