#!/usr/bin/perl
use strict;
use File::Find;
undef $/;
my %dict;
my $options = {
wanted => \&process,
no_chdir => 1
};
find($options, '.');
print_dict(\%dict);
sub print_dict {
my $dict = shift;
foreach my $word (sort keys %{$dict}) {
print "
$word
";
foreach my $file (sort keys %{$dict->{$word}}) {
print "- $file (" . $dict->{$word}{$file} . ")
\n";
}
print "\n";
}
}
sub process_text {
my $file = shift;
#my %dict;
#print "HTML: processing $file...\n";
open(IN, $file) or die "Error opening $file: $!\n";;
my $contents = ;
my @words = ($contents =~ /\w+/g);
foreach my $word (@words) {
$dict{lc($word)}{$file}++;
}
}
sub process {
my $file = $File::Find::name;
print "Trying $file... ";
if($file =~ /\.(html|txt|tex)$/i) {
process_text($file);
}
print "(" . (scalar keys %dict) . ")\n";
}