Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Junk NOT words

by fruiture (Curate)
on Oct 30, 2002 at 17:51 UTC ( #209174=note: print w/ replies, xml ) Need Help??


in reply to Junk NOT words

sub resolve { my $strref = shift; my $strpos = shift; my $dictfh = shift; return [] if length($$strref) == $strpos; my $words; my $reset_fh = tell($dictfh); seek $dictfh,0,0; while(defined(local $_ = <$dictfh>)){ chomp; if( substr($$strref,$strpos,length) eq $_ ){ print "$_ at $strpos\n"; if( my $w = resolve($strref,$strpos+length,$dictfh) ){ $words = [$_,@$w]; last; } print "<- $strpos\n"; } } seek $dictfh,$reset_fh,0; return $words; } open my $dfh,'<','/usr/dict/words' or die $!; my $string = 'whererangesarealltherage'; my $words = resolve( \$string, 0, $dfh ); print $words ? "@$words" : 'no words' , "\n"; close $dfh;

I've included some output that shows how the program "backtracks".

--
http://fruiture.de


Comment on Re: Junk NOT words
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2014-08-27 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (247 votes), past polls