Quicksilver has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $word = "scrooge"; my @find = map ([split //], $word); my $find_len = length($word); my $fuzzy = 2; while (my $search = <DATA>) { chomp $search; $search = [split //, $search]; for my $i ( 0..@$search-$find_len ) { FIND: for my $find ( @find ) { my $misses = 0; for $j ( 0..$find_len-1 ) { $misses++ if $search->[$i+$j] ne $find->[$j]; next FIND if $misses > $fuzzy; } print "Line $. Match ($misses) at $i, @$search\n"; } } } __DATA__ STAVE I: MARLEY'S GHOST MARLEY was dead: to begin with. There is no doubt whatever about that. The register of his burial was signed by the clergyman, the clerk, the undertaker, and the chief mourner. Scrouge signed it: and Scrooge's name was good upon 'Change, for anything he chose to put his hand to. Old Marley was as dead as a door-nail. Mind! I don't mean to say that I know, of my own knowledge, what there is particularly dead about a door-nail. I might have been inclined, myself, to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors is in the simile; and my unhallowed hands shall not disturb it, or the Country's done for. You will therefore permit me to repeat, emphatically, that Marley was as dead as a door-nail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to find a word in a fuzzy search algorithm
by Limbic~Region (Chancellor) on Jun 04, 2008 at 14:45 UTC | |
by Quicksilver (Scribe) on Jun 04, 2008 at 15:25 UTC | |
|
Re: Trying to find a word in a fuzzy search algorithm
by moritz (Cardinal) on Jun 04, 2008 at 15:37 UTC | |
|
Re: Trying to find a word in a fuzzy search algorithm
by Crackers2 (Parson) on Jun 04, 2008 at 18:06 UTC |