Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

help with minimal matches

by Anonymous Monk
on Mar 18, 2001 at 10:42 UTC ( #65241=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can someone help or direct me to the answer?

I have a flattext dbase. I want to let people search by inputing their search strings. But I want to minimize the matches to only 4-5 characters. Ok, that was not very clear.

Let's say the item in my dbase is "saturday".
The input "is today saturd or sunday?" or "atur"

Basically, I want to return "abc4567def" as a match when the users query with either "1234567890" or
"---4567-----" or "4567".

The minimal match function does not seem to fit this case

Thank you for any help. Danny

Comment on help with minimal matches
Replies are listed 'Best First'.
Re: help with minimal matches
by Anonymous Monk on Mar 18, 2001 at 13:29 UTC
    my $search = 'is today saturd or sunday?'; my $record = 'saturday'; my $pattern; my @chars; my @patterns; my $len = 4; @chars = split(//, $search); for(my $i = 0; $i <= length($search) - $len; $i++) { push(@patterns, quotemeta(join('', @chars[$i .. $i + $len - 1]))); } $pattern = '(?:'.join('|', @patterns).')'; if($record =~ /$pattern/) { print "Match with pattern $pattern\n"; }
Re: help with minimal matches
by I0 (Priest) on Mar 19, 2001 at 04:53 UTC
    use String::Approx 'amatch'; @matches = amatch("saturday", ['4S0I0'], "is today saturd or sunday?", + "atur"); @matches = amatch("abc4567def", ['6S0I0'], "1234567890", "---4567----- +", "4567");
Re: help with minimal matches
by Anonymous Monk on Mar 19, 2001 at 11:30 UTC
    Thanks for the help. Danny.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://65241]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2016-02-12 00:59 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (386 votes), past polls