in reply to Comparison between keys in hash
PD to perlmonks admins: I really hate to have add <br> in every line :( when I'm commenting or posting#! /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-1;$i++) { $t1="$arr1[$i] $arr1[$i+1] $arr1[$i+2]"; if(@matchs=$str2=~/($t1)/g) { $result{@matchs}=$t1; print $i+1,"\t\t",scalar @matchs,"\t\t\t$t1\n"; $n++; } if(@matchs=$str1=~/($t1)/g) { $output{@matchs}=$t1; print $i+1,"\t\t",scalar @matchs,"\t\t\t$t1\n"; } } print "\n\nTotal Matches : $n\n"; if ((sort keys %output)[0] > (sort keys %result)[0]) { print "result has the minor value\n"; } elsif ((sort keys %output)[0] < (sort keys %result)[0]) { print "output has the minor value\n"; } else { print "Both has the same minor value\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparison between keys in hash
by MidLifeXis (Monsignor) on Jul 06, 2011 at 15:09 UTC | |
by i5513 (Pilgrim) on Jul 06, 2011 at 16:48 UTC | |
|
Re^2: Comparison between keys in hash
by zek152 (Pilgrim) on Jul 06, 2011 at 15:12 UTC | |
|
Re^2: Comparison between keys in hash
by sarvan (Sexton) on Jul 06, 2011 at 15:06 UTC | |
by i5513 (Pilgrim) on Jul 06, 2011 at 16:40 UTC | |
by sarvan (Sexton) on Jul 07, 2011 at 06:14 UTC | |
by i5513 (Pilgrim) on Jul 07, 2011 at 08:11 UTC | |
by sarvan (Sexton) on Jul 07, 2011 at 10:33 UTC | |
| |
by jdporter (Paladin) on Jul 06, 2011 at 15:09 UTC | |
by Anonymous Monk on Jul 06, 2011 at 15:16 UTC |