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 :-)


In reply to Re: How grep IP-addresses that is an exact match? by wolfi
in thread How grep IP-addresses that is an exact match? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.