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

Many thanks Athanasius ))

So amatch tries to match every word in @list even after one has been found? If the list is huge, would it be very slow?

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

  • Comment on Re^2: Getting matched word from String::Approx

Replies are listed 'Best First'.
Re^3: Getting matched word from String::Approx
by Athanasius (Archbishop) on Dec 30, 2015 at 13:15 UTC
    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,

      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