Splitting into letters seems more cumbersome than using regular expressions:
use strict; use warnings; my @lexikon = qw/ own known /; my $word = "unknown"; my $longestmatch = ""; foreach my $w (@lexikon) { if( $word =~ /$w$/ ) { $longestmatch=$w if length($w)>length($longestmatch); } } # $longestmatch now has the longest match $word =~ /(.*)($longestmatch$)/; print "$1+$2\n";
In reply to Re: Longest String Matching
by hdb
in thread Longest String Matching
by Dr Manhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |