Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Longest String Matching

by choroba (Abbot)
on Apr 08, 2013 at 11:57 UTC ( #1027477=note: print w/ replies, xml ) Need Help??

in reply to Longest String Matching

You can use rindex to find the last occurrence of a substring in a string:

#!/usr/bin/perl use warnings; use strict; my @lexikon = sort { length $b <=> length $a } qw/ own known /; my $word = "unknown"; print rightside($word), "\n"; sub rightside { my $word = shift; my $length = length $word; for my $l (@lexikon) { return $l if $length - length $l == rindex $word, $l; } return q(); }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Comment on Re: Longest String Matching
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-26 07:57 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (175 votes), past polls