http://www.perlmonks.org?node_id=1027479


in reply to Re: Longest String Matching
in thread Longest String Matching

I do not think it can get much better. My proposal is not very useful for large dictionaries...

Replies are listed 'Best First'.
Re^3: Longest String Matching
by space_monk (Chaplain) on Apr 08, 2013 at 12:08 UTC
    Thanks; Maybe my solution is better than I first thought! :-)
    A Monk aims to give answers to those who have none, and to learn from those who know more.

      Adding the empty string to the lexikon allows the following shortening:

      $lookup{''} = 1; substr($word, 0, 1) = "" while !exists $lookup{$word};