Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Longest String Matching

by Rahul6990 (Beadle)
on Apr 08, 2013 at 12:03 UTC ( #1027480=note: print w/ replies, xml ) Need Help??


in reply to Longest String Matching

try this:

%wordlist= ("unknown", -1); %lexicon = ("own", 1, "known", 1); foreach my $q (keys %wordlist) { push (@array, split(//, $q)); $end = $#array; $mover = 1; print "\nend : $end \nmove : $mover\n"; &rightside(); print "$right\n"; @array = (); } sub rightside { last if($mover == 0 or $move == $end); if (exists $lexicon{join q(), @array[$mover..$end]}) { $right = join q(), @array[$mover..$end]; print "\nright:$right\n"; } else { $mover++; &rightside(); } }
the problem in your code was, you were starting with the smallest string ($mover = 2 and $end = 6)which always return 'own' thats why the output was showing 'own'. Now we are starting with the largest possible string and keeps on reducing the string size till we find the matched string in lexicon or the string length becomes 0.


Comment on Re: Longest String Matching
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-01-29 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My top resolution in 2015 is:

















    Results (235 votes), past polls