Whenever you want to look things up, and they are not sequentially numbered, think about using a hash instead of an array.
I'm not sure exactly what you need, but I'll take a guess.
Consider an example where you have a hash of terms and the documents they apply to:
my %table = (
recent => {'c:/autoexec.bat'=>undef, 'c:/frog.jpg'=>undef},
text => {'c:/autoexec.bat'=>undef, 'c:/classnotes.txt'=>undef},
biology => {'c:/classnotes.txt'=>undef, 'c:/frog.jpg'=>undef},
);
Building the table, would be a matter of going through each file, and setting $table{$term}{$filename} = undef; for each term that the file matches.
You could then determine which documents match 'recent and biology', via:
my @terms = ('recent', 'biology');
my @matches = keys %{ $table{ (shift @terms) } };
foreach my $term (@terms)
{
@matches = grep { exists $table{$term}{$_} } @matches;
}
printf "Found %05d matches!\n", scalar @matches;
Of course, this example only does searches with all terms required. For boolean operations on your search terms, you'd want to make a tree and combine or intersect (or xor or whatever) the hashes at each node. |