Text::Fuzzy has a maximum distance setting. set_max_distance of Text::Fuzzy.

It seems not to have a function that will return matched strings with their distances, but you could iterate over the data yourself using the distance method. See code below for an example.

I think the nearest method in list context will return the list of strings with the shortest distance, so will not be all those within the maximum distance. Both those would be useful to have - maybe submit a feature request?

# code not tested my $max_distance = 4; my $some_label = 'blortbertblart'; my %targets_hash = (...); my $distance_finder = Text::Fuzzy->new( $some_label, trans => 1); $distance_finder->set_max_distance ($max_distance); my %poss_matches; foreach my $target (keys %targets_hash) { my $distance = $distance_finder->distance( $target_label ); next if !defined $distance; $poss_matches{$distance} //= []; push @{$poss_matches{$distance}}, $target; } # do stuff with @poss_matches

In reply to Re^2: Text::Fuzzy recursive fuzzy_index by swl
in thread Text::Fuzzy recursive fuzzy_index by Anonymous Monk

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.