Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Print only the matched line when process line by line from a file

by davido (Cardinal)
on Mar 21, 2018 at 19:10 UTC ( [id://1211450]=note: print w/replies, xml ) Need Help??


in reply to Print only the matched line when process line by line from a file

So the question is how to put more than one condition into the initial if()?

if (/Grapes/ || /strawberry/i) { print; } else { print "$_ is not in the list.\n"; }

Or in this case you could leverage the power of alternation within the regular expression:

if (/Grapes|(?i:strawberry)/) { .... } else { .... }

If the behavior is supposed to differ based on what matched, you could also do this:

if(/foo/) { # do something } elsif (/bar/) { # do something else } else { # complain about falling through }

Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-23 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found