Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How do I get an exclusion with grep?

by hippo (Bishop)
on Apr 27, 2020 at 08:24 UTC ( [id://11116115]=note: print w/replies, xml ) Need Help??


in reply to How do I get an exclusion with grep?

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.

Replies are listed 'Best First'.
Re^2: How do I get an exclusion with grep?
by Lady_Aleena (Priest) on Apr 27, 2020 at 09:22 UTC

    Thank you hippo, that worked! 8)

    My OS is Debian 10 (Buster); my perl version is 5.28.1.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found