Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: File::Find find several strings in one directory

by stevieb (Canon)
on May 09, 2017 at 17:24 UTC ( #1189926=note: print w/replies, xml ) Need Help??


in reply to File::Find find several strings in one directory

You can use grouping with the or operator within the regex, combined with word boundaries:

use warnings; use strict; use feature 'say'; my @strings = ( "Bob said hello\n", "Alice doesn't like Chris\n", "This line won't match\n" ); for (@strings){ say "yay!" if /(?:\bAlice\b|\bBob\b|\bChris\b)/; }

That says:

/ (?: # group, but don't capture \bAlice\b # capture Alice, if it is standalone | # or \bBob\b # same as Alice above | # or \bChris\b # same as Alice and Bob ) # end grouping /

Replies are listed 'Best First'.
Re^2: File::Find find several strings in one directory
by Staralfur (Novice) on May 09, 2017 at 18:06 UTC

    Thank you, I will try it!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-08-17 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?