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

Re: Need to multi grep and grep exclude in perl.

by kcott (Archbishop)
on Feb 23, 2016 at 15:45 UTC ( [id://1155930]=note: print w/replies, xml ) Need Help??


in reply to Need to multi grep and grep exclude in perl.

G'day Frits,

I'm familiar with grep, egrep and fgrep but not ggrep. Please provide a link to documentation or a brief description of how it differs from grep.

Here's how you can do the "multi grep and grep exclude" part:

grep { /Country/ && /City1/ && /Street1/ && ! /name1/ } ...
"this grep will be in a foreach loop"

Why? Please provide some code to show what you're doing.

As already stated by others, your requirements are unclear. Here's my best guess as to the type of thing you want.

#!/usr/bin/env perl -l use strict; use warnings; while (<DATA>) { if ((my $result) = grep { /Country/ && /City1/ && /Street1/ && ! / +name1/ } $_) { print +(split ' ', $result)[4]; last; } } __DATA__ Country City Street1 number1 name1 Country City1 Street1 number1 name2 Country City1 Street1 number2 name3 Country City1 Street2 number1 name4 Country City1 Street2 number1 name5

Output:

name2

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found