# concordance - create a list of all places in a set of files where a given
# set of words occurs
use MakeRegex;
my @list= qw(arm back leg elbow ear eye chin cheek knee head hip tooth teeth lips mouth hair);
$dir = "c:\\temp\\";
concordance($dir,\@list);
exit;
sub concordance {
($dir,$list) = @_;
# makeregex from word list
my($regex) = MakeRegex::make_regex(@$list);
print "regex: $regex\n";
opendir(DIR,$dir) or die "Can't open $dir: $! \n";
#iterate over all the files in a directory
@files = readdir(DIR);
foreach $file (@files) {
if (-f "$dir\\$file") {
print "infile: $dir\\$file\n";
open(INFILE,"$dir\\$file") or die "Can't open file $file for input\n";
# iterate over the lines of the file
$line_no = 1;
while($line = ) {
if ($line =~ /($regex)/) {
$word = $1; # first word matched in a line
print "($word,$file,$line_no): $line\n";
}
$line_no++;
}
close(INFILE);
}
}
closedir(DIR);
}
# next:
# invertfile - create an index for a set of keywords in a set of files.
# (word;line;para,char)
# can't smush all lines of a file into one gigantic string because
# the files that hold literary works can often be quite big.
               (
geocities.com/soho/square)                   (
geocities.com/soho)