This sounds like a great programming exercise while I drink my morning coffee...

#!/usr/bin/perl use strict; use warnings; my $string = '2raccoon49-racing'; my @tests = qw(Winnie Pooh racat Bats xyz35 Barack ccoons acc 2ra); print "\n\nOur search string is : \"$string\"\n\nMinimum number of let +ters that must match.\n|\n|\nV"; foreach (@tests) { print "\t$_"; } for (my $N = 1; $N < 7; $N++) { print "\n$N"; foreach (@tests) { print "\t", PartialMatchStr($string, $_, $N); } } print "\n\n"; ################################################## # This function performs a partial match and returns 1 # if at least N bytes of string1 and string2 match # anywhere. Returns zero otherwise. # # Usage: INTEGER = PartialMatchStr(STR1, STR2, N) # sub PartialMatchStr { @_ > 2 or return 0; foreach (@_) { defined $_ or return 0; } my $N = $_[2]; my $L = length($_[1]) - $N; if (length($_[0]) < $N || $L < 0) { return 0; } # Impossible for (my $i = 0; $i <= $L; $i++) { # Take one segment from STR1 and find it within STR2. if ( index($_[0], substr($_[1], $i, $N) ) >= 0) { return 1; } } return 0; } ##################################################

In reply to Re: Finding a partial match by harangzsolt33
in thread Finding a partial match by jpys

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.