in reply to Getting matched word from String::Approx
There could be more than one word matched, so try this:
#! perl use strict; use warnings; use String::Approx qw(amatch); my @list = qw(Apple Pear Orange); my @inputs = qw(aple appe peay range oranges mango appple aqqple); for my $word (@inputs) { my @matches = amatch($word, ['i'], @list); if (@matches) { print "Matched: $word to: ", join(', ', @matches), "\n"; } else { print "Unmatched: $word\n"; } }
Output:
22:27 >perl 1501_SoPW.pl Matched: aple to: Apple Matched: appe to: Apple Matched: peay to: Pear Matched: range to: Orange Matched: oranges to: Orange Unmatched: mango Matched: appple to: Apple Unmatched: aqqple 22:27 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting matched word from String::Approx
by Anonymous Monk on Dec 30, 2015 at 12:44 UTC | |
by Athanasius (Archbishop) on Dec 30, 2015 at 13:15 UTC | |
by Anonymous Monk on Dec 30, 2015 at 16:17 UTC | |
by ww (Archbishop) on Dec 30, 2015 at 18:45 UTC | |
by Anonymous Monk on Jan 01, 2016 at 02:34 UTC |