Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: search of a string in another string with 1 wildcard

by choroba (Abbot)
on Jul 29, 2014 at 09:30 UTC ( #1095478=note: print w/ replies, xml ) Need Help??


in reply to Re: search of a string in another string with 1 wildcard
in thread search of a string in another string with 1 wildcard

This seems similar to Multiple Approximate Pattern Matching Problem. Here's my solution:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; chomp(my $text = <>); my @patterns = split ' ', <>; my $threshold = 0 + <>; my @ctext = split //, $text; my @results; for my $pattern (@patterns) { my @cpat = split //, $pattern; POSITION: for my $pos (0 .. @ctext - @cpat) { my $mismatches = 0; for my $i (0 .. @cpat - 1) { if ($cpat[$i] ne $ctext[$pos + $i]) { next POSITION if ++$mismatches > $threshold; } } push @results, $pos; } }; say join ' ', sort { $a <=> $b } @results;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^2: search of a string in another string with 1 wildcard
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1095478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-11-23 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls