Wow, looks like perl is too clever for its own good. You feed it the string "Reuel T" and it magically translates it to "R Tolkien". Now that's DWIM taken too far!

Beside that inconsistency between your input and the output you say you have, your exemple does not illustrate well what you meant by "best match", because in all cases the search string is fully contained in one of the sources. ("John Ronald Reuel T" and "<John Ronald Reuel T>olkien"). If your original search string was indeed "John Ronald R Tolkien", I suppose you'd still want to match "John Ronald Reuel Tolkien"?

And FYI, you can do all this:

#gets first two names (my $twonames=$s)=~s/^(\w+ \w+).*$/$1/; #gets all other names, if they exist (my $others=$s)=~s/^(\w+ \w+)//; #deletes initial space (my $alternativesearch=$others)=~s/^\s//;
in one line (see "matching in list context" in Quote and Quote like Operators): my ($twonames, $others) = /^(\w+ \w+)(?: (.+))?/;


In reply to Re: Searching for best match by Eily
in thread Searching for best match by Sosi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.