Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Longest String Matching

by choroba (Canon)
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 pondering the Monastery: (5)
As of 2016-02-07 00:31 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (238 votes), past polls