The suggestions so far don't really do what you said you wanted done.

1) All lines starting with a particular IP.

2) Assuming "bung"="add" that it's an additive thing, not an overwrite thing.

my @ip while (<LOG>) { #assuming you are looping through a log file my $log = $_; #making this blatent push(@ip, $log) if $log =~ /^192\.168\.1\.10/;
From your code, the 'g' modifier means match as many times as possibe.

From mine, '^' is an anchor to the begining of the string.

From your code, '@ip = $log' overwrites the values of $ip[0] each time.

From my code, 'push(@ip, $log)' adds the entire line to the end of the array.

Update: diotalevi's concept of using index instead of a regexp was an excellent suggestion that avoids regex engine overhead, so . . .

push(@ip, $log) if 0 == index($log,'192.168.1.10');
Which gives you those that start with the ip in question.

In reply to Re: and a simple reg exp poser by Cabrion
in thread and a simple reg exp poser by stew

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.