in reply to Re^2: Getting matched word from String::Approx
in thread Getting matched word from String::Approx

If the list is huge, would it be very slow?

Quite possibly. There’s a discussion in String::Approx#CONTROLLING-THE-CACHE about the tradeoffs between memory and running time.

If we just wanted to get the first match from @list and return the result, is there a way to do that?

From the documentation, this doesn’t seem to be possible, no. :-( When called in scalar context, the amatch function returns a single value, but that value is just true or false to indicate whether or not any matches were found.

Note: Before committing to this module, you should read String::Approx#DESCRIPTION carefully and consider the alternatives. Depending on your requirements, a module such as Text::Levenshtein might suit you better.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^4: Getting matched word from String::Approx
by Anonymous Monk on Dec 30, 2015 at 16:17 UTC

    Great thanks for your helpful advice and suggestions.

    I intended to use the module for a web-based search function for products. So if a user types a search string that is close to one of the products, then that product name will be suggested to the user. Since more than one match may be returned, I guess I will display the matched products as suggestions.

    Would that be considered appropriate in your opinion?

      Depends on your definition of "appropriate and -- if you're writing this for a third party, what the third party considers "appropriate."

      Matches such as you listed don't give me any heartburn... except, that is, the annoyance which grows out of getting [some|many|mostly} irrelevant responses to straightforward search terms.

      And there are obvious approximate matches that may annoy some of your hypothetical users. But stop without reading more if scatological phrases bother you.

      And what if your user-entered word matches something offensive in another language? These are just a few of the issues you need to resolve.

      Quis custodiet ipsos custodes. Juvenal, Satires

        Thanks for responding, ww.

        I don't really know but I suspect a response that suggests possible words of the mistyped word is more helpful that one than one that says "Your search string does not match any product.", for example. Especially if the user doesn't know the exact spelling of the word?