Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-10-31 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls