#! perl -sw use strict; use Benchmark::Timer; use vars qw[$SEED]; # We'll pass it as ref to SCALAR and receive it in a ref to ARRAY use constant ARTICLES => 100; use constant ENTRIES => 2000; my $t = Benchmark::Timer->new(); srand( $S || 1 ); $t->start('Using scalar grep to count occurances'); my( @A, @E, %X ); my( %A ); #Articles foreach my $article ( 1 .. ARTICLES ) { foreach my $feature ( 1 .. 10 ) { $A[$article][$feature] = int rand(100); } } #Entries foreach my $entry ( 1 .. ENTRIES ) { foreach my $feature ( 1 .. 10 ) { $E[$entry][$feature] = int rand(100); } } $| += 1; foreach my $article ( 1 .. ARTICLES ) { foreach my $entry ( 1 .. ENTRIES ) { my $count = grep{ $E[$entry][$_] eq $A[$article][$_] } 1 .. 10; push @{ $X{$article} }, $entry if $count >= 3; } } foreach my $article ( sort { $a <=> $b } keys %X ) { print "$article:"; foreach my $entry ( @{ $X{$article} } ) { print "\t$entry"; } print "\n"; } $t->stop('Using scalar grep to count occurances'); $t->report;