Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Longest String Matching

by hdb (Monsignor)
on Apr 08, 2013 at 11:49 UTC ( [id://1027474]=note: print w/replies, xml ) Need Help??


in reply to Longest String Matching

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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found