Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Finding dictionary words in a string.

by Anonymous Monk
on Mar 13, 2004 at 04:32 UTC ( [id://336332]=note: print w/replies, xml ) Need Help??


in reply to Finding dictionary words in a string.

My first stab:

#!c:/perl/bin/perl -w use strict; my %index; open my $fh, '<', 'dict.dat' or die "open failed: $!"; while (<$fh>) { chomp; next if length($_) < 3; push @{$index{ lc(substr($_, 0, 3)) }}, $_; } close $fh; #print join(', ', map { @$_ } $index{'rad'}), $/; my $str = 'owijfwapplelaskfiwejfcherryalkfwiofwfblossomowiejf'; for my $i (0 .. length($str)-3) { for my $j (3..length($str)-$i) { my $substr = substr($str, $i, $j); my $index = substr($substr, 0, 3); next unless exists($index{$index}); for (map { @$_ } $index{$index}) { print $_, $/ if $_ eq $substr; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://336332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-28 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found