Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How grep IP-addresses that is an exact match?

by wolfi (Scribe)
on Apr 03, 2004 at 08:07 UTC ( [id://342243]=note: print w/replies, xml ) Need Help??


in reply to How grep IP-addresses that is an exact match?

i believe, i've been doing an almost identical routine lately to what you've got there. When i first began, i kept getting the same results (and frustration), that you've gotten. The others touched on the key for me in their examples, but i thought, i would elaborate on what's going on.

say, you have... $host = 1.2.3.4
and you search for /$host/

you could get back...
1.2.3.4
11.2.3.4
201.2.3.4
1.2.3.43
1.2.3.42
111.2.3.49
or even... cat1.2.3.4dog

because perl regexes are so greedy in nature. The keys to changing this behavior for me were the addition of -
the caret ^ symbol - which is a beginning-anchor ("nothing before")
and the dollar sign $ - which is an ending-anchor ("nothing after")

these'll let perl know, you are searching for one specific expression. I use'em almost religiously now in those kinds of pattern matches.

assuming that each $host(@ip_host) entry is an ip addy in the same format, i would think, that simply grepping /^$host$/ would work.

either way, hope it works out for you :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-03-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found