I found that $text needs to be an exact match. I would prefer not having to use exact matches. I added case insensitivity to it also.
This suggests to me that you might be performing the match the wrong way round, i.e. you want to look case-insensitively within $text for things which match the patterns held in @big_images. If that's the case then you need to switch the grep so that $_ becomes the pattern. e.g.:
$class .= ' right' unless grep($text =~ /$_/i, @big_images);
Here's the SSCCE:
use strict; use warnings; use Test::More tests => 4; my $text = 'Only smartees have the answer!'; ok grep ($text =~ /$_/i, 'Smart'), 'Case-insensitive match'; ok grep ($text =~ /$_/i, 'foo', 'Smart', 'bar'), 'Match one of three'; ok grep ($text =~ /$_/i, 'foo', 'Smart', 'art'), 'Match two of three'; ok !grep ($text =~ /$_/i, 'foo', 'baz'), 'Match none';
HTH.
In reply to Re: How do I get an exclusion with grep?
by hippo
in thread How do I get an exclusion with grep?
by Lady_Aleena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |