Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How do I get an exclusion with grep?

by AnomalousMonk (Archbishop)
on Apr 27, 2020 at 05:58 UTC ( [id://11116102]=note: print w/replies, xml ) Need Help??


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

... I do not want right appended to $class if Smart is in $text.

Your code seems to me to do what you want.

c:\@Work\Perl\monks>perl -wMstrict -le "my @big_images = qw(xsMaRty Dull Boring); ;; my $text = 'Smart'; ;; my $class = 'svg_group'; $class .= ' right' unless grep(/$text/i, @big_images); ;; print qq{'$class'}; ;; $text = 'Xxx'; ;; $class = 'svg_group_2'; $class .= ' left' unless grep(/$text/i, @big_images); ;; print qq{'$class'}; " 'svg_group' 'svg_group_2 left'
In the first case, Smart is in $text and right is not appended. In the second case, Smart is not in $text and left is appended.

Update: You may also be interested in any and none in List::Util.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found