in reply to Re^2: Comparison between a string and an array
in thread Comparison between a string and an array
$match = 'Ba'; @array = ('Bad','Good','Whatever'); if (grep(/$match/, @array)) { print "Yippie!\n"; } else { print "No Match\n"; }
If you enclosed the variable $match in word boundaries as followed
grep(/\b$match\b/, @array)
It would no longer match do to the fact that the match must match the exact string passed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Comparison between a string and an array
by AnomalousMonk (Archbishop) on May 05, 2015 at 17:24 UTC | |
by edimusrex (Monk) on May 05, 2015 at 19:50 UTC |