#!/usr/bin/perl use strict; use warnings; use File::Basename; my $num_args = $#ARGV + 1; if($num_args > 0) { my @lists = ("filter", "thought", "weasel"); my %full_list; my $basedir = dirname($0); # Read the trouble words for my $list (@lists) { my $list_path = sprintf("%s/%s-words.txt", $basedir, $list); #print "$list_path\n"; open(LIST, $list_path); foreach my $line () { my $word = substr($line, 0, -1); $full_list{$word} = 0; # dummy value } close(LIST); } foreach my $file (@ARGV) { open(FILE, $file); my $line_num = 0; foreach my $line () { ++$line_num; foreach my $word (keys %full_list) { my $offset = 0; my $sub = $line; while(length($sub) > 0) { if ($sub =~ m/\b$word\b/i) { $offset += length($`); print "$file $word ($line_num:$offset)\n"; $offset += length($word); $sub = $'; } else { $sub = ""; } } } } close(FILE); } } else { print "Usage: ${0} [filename2 filename3 ...]\n"; }