use strict; use Text::Soundex; use LWP::Simple; use HTML::Entities; $Text::Soundex::nocode = 'Z000'; $| = 1; print "Loading.."; my @nodes = map {($_)=/"([^"]+)"/;defined($_)?[$_,soundex($_)=~/(.)(.{3})/]:['','Z',0]} split /\n/, get 'http://perlmonks.org/?node_id=74291'; print "Done.\n"; s/(\w+)/bestfit($1)/ge, print while <>; sub bestfit { my($word) = @_; my @se = soundex($word)=~ /(.)(.{3})/; return "[nodereaper|$word]" if join('',@se) eq 'Z000'; my @found = sort {abs($se[1]-$a->[2]) <=> $se[1]-$b->[2]} grep {$se[0] eq $_->[1]} @nodes; return "[".decode_entities $found[rand(grep {$found[0][2] == $_->[2]} @found)]->[0]."|$word]"; }