lemnar has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl $op = shift @ARGV; # load a list of valid words unless ($op =~ /^S$/) { open WORDLIST, shift @ARGV; while (<WORDLIST>) {chomp;push @words, $_;} close WORDLIST; } else { while(<>){push @correct;} } # find a list of possible words from the list of valid words if ($op =~ /^P(.{0,2})(.)(.{1,})$/) {($otherop,$direction,$letter)=($1 +,$2,$3); for (@words) { if ($direction eq "F") { if (/\b($letter)/) {push @possible, $';} } elsif ($direction eq "B") { if (/($letter)\b/) {push @possible, $`;} } } if (!$otherop) {for(@possible){print "$_\n";}} } # check the list of possible words against the list of valid words if ($op =~ /^(.?)C(S*)/) {$otherop = $2; if (!$1) {while(<>){push @possible, $_;}} for $word (@words) { for(@possible) { if ($word eq $_) {push @correct, $_;} } } if (!$otherop) {for(@correct){print "$_\n";}} } # sort the list of correct words by size (small to large) and then abc if ($op =~ /^(.*)S/) { if ($op =~ /S$/) {while(<>){push @correct, $_;}} @sorted = sort { length $a <=> length $b or $a cmp $b } @correct; for(@sorted) {print "$_\n";} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: speedier text matching
by Zaxo (Archbishop) on Aug 07, 2004 at 00:49 UTC | |
|
Re: speedier text matching
by Aristotle (Chancellor) on Aug 07, 2004 at 00:48 UTC | |
|
Re: speedier text matching
by ysth (Canon) on Aug 07, 2004 at 01:00 UTC |