in reply to non-exact regexp matches
why does it need to be in a regexp? Sounds like you just want a string comparator, unless you have more complex patterns in mind.
$str = 'PolarBear'; my @str = split//,$str; my @pats = qw(polarbear Polerbear Polarbeer); for (@pats) { my @mat = mismatches($_,$str); print "Mismatches for $_ vs $str: @mat\n"; } sub mismatches { my ($p1,$p2) = @_; my @foo = split//,$p1; my @str = split//,$p2; my @pos; if ($#foo > $#str) { for (0 .. $#foo) { push @pos, $_ if $foo[$_] ne $str[$_]; } } else { for (0 .. $#str) { push @pos, $_ if $foo[$_] ne $str[$_]; } } return @pos; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: non-exact regexp matches
by vinforget (Beadle) on Jun 23, 2004 at 19:05 UTC |
In Section
Seekers of Perl Wisdom