# Matching algorithms

Torsten Knorr create-soft at tiscali.de
Sun Jun 29 19:49:25 BST 2008

```#!/usr/bin/perl -w
#*** compare.pl ***#
#-------------------------------------------------
use strict;
use warnings;
#-------------------------------------------------
my @source = (1, 5, 7);
my @sets = (
[ 1, 3, 6, 7 ],	[1, 5, 7],		['1', '2', '3'],
[ 2, 4, 7, 9 ],	[0, 1, 2, 3, 4, 5, 6],	[qw(5 6 7 8)],
[ 7, 3, 5, 2 ],	[1, 1, 1, 1, 1, 1],	[(7) x 20],
[ 1, 5, 7, 9 ],	[1..10],	[7 x 20],
[ 99, 99, 0, 0 ],	[7],	[qw(one two)],
);
#-------------------------------------------------
print("Looking for similarity with: " . join(',', @source) . "\n");
my \$rh_result = CompareSets(\@source, \@sets);
print(join(',', @{\$sets[\$_]}) . " = \$rh_result->{\$_} matchs\n") for(keys(%\$rh_result));
#-------------------------------------------------
sub CompareSets
{
my (\$ra_source, \$ra_sets) = @_;
my \$rh_result;
for(my \$i = 0; \$i <= \$#\$ra_sets; \$i++)
{
for my \$item (@{\$ra_sets->[\$i]})
{
\$rh_result->{\$i} += grep { "\$item" eq "\$_" } @\$ra_source;
}
}
return \$rh_result;
}
#-------------------------------------------------
# BR Torsten

```