Hi,
I have articles table and entries table which contains records. Each record has feature and corresponding values. Each record can have different number of features from a fixed set, and it can carry different values. Set of values is not fixed however. I am trying to find out all the entries which has atleast 3 matching features and values for a given article.

Currently my code take long amount of time to run.

# We'll pass it as ref to SCALAR and receive it in a ref to ARRAY use constant ARTICLES => 100; use constant ENTRIES => 2000; #Articles foreach $article ( 1 .. ARTICLES ) { foreach $feature ( 1 .. 10 ) { $A->{$article}{$feature} = int rand(100); } } #Entries foreach $entry ( 1 .. ENTRIES ) { foreach $feature ( 1 .. 10 ) { $E->{$entry}{$feature} = int rand(100); } } $| += 1; foreach my $article ( 1 .. ARTICLES ) { foreach $entry ( 1 .. ENTRIES ) { # print "." if $entry % 1000 == 0; my $count; foreach $feature ( 1 .. 10 ) { if ( $E->{$entry}{$feature} eq $A->{$article}{$feature}){ $count += 1; } } if ( $count >= 3 ) { #Found match push @{ $X->{$article} }, $entry; } } } foreach my $article ( sort { $a <=> $b } keys %{$X} ) { print "$article:"; foreach my $entry ( @{ $X->{$article} } ) { print "\t$entry"; } print "\n"; }
Sample Output:
1:	1120
7:	1563
12:	341
24:	4
25:	1977
28:	455
30:	143
36:	618
43:	802
44:	107
48:	263
50:	1824
53:	1734
60:	1778
64:	350	448
71:	1673
72:	691
75:	780
76:	265	1669
80:	1260
85:	1429	1966
98:	758
99:	60
Any better and faster method would be useful. Currently it works fine, but for 10000 articles and 200,000 entries, this takes a lot of time.
Thank you, br>artist.

In reply to Articles matching entries by artist

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.