I have a file which needs to be parsed to get some parameters. It looks like
1, , , Transport, TCP,Total Packets with Er +rors = 0 1, , , Transport, TCP,Packets Received w +ith Checksum Errors = 0 1, , , Transport, TCP,Packets Received w +ith Bad Offset = 0 1, , , Transport, TCP,Packets Received t +hat are Too Short = 0 1, ,[1024], Application,TRAFFIC-GEN Server,Client Add +ress = 192.0.0.6 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +art Time (s) = 0.226811597 1, ,[1024], Application,TRAFFIC-GEN Server,Session En +d Time (s) = 19.909754409 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +atus = Closed 1, ,[1024], Application,TRAFFIC-GEN Server,Total byte +s Received = 8320 1, ,[1024], Application,TRAFFIC-GEN Server,Total Data + Units Received = 260 1, ,[1024], Application,TRAFFIC-GEN Server,Throughput + (bits/s) = 3381 1, ,[1024], Application,TRAFFIC-GEN Server,Average En +d-to-End Delay (s) = 0.026102975 1, ,[1024], Application,TRAFFIC-GEN Server,Average Ji +tter (s) = 0.070900925 1, ,[1024], Application,TRAFFIC-GEN Server,Client Add +ress = 192.0.0.4 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +art Time (s) = 0.107537260 1, ,[1024], Application,TRAFFIC-GEN Server,Session En +d Time (s) = 19.984968334 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +atus = Closed 1, ,[1024], Application,TRAFFIC-GEN Server,Total byte +s Received = 11232 1, ,[1024], Application,TRAFFIC-GEN Server,Total Data + Units Received = 351 1, ,[1024], Application,TRAFFIC-GEN Server,Throughput + (bits/s) = 4520 1, ,[1024], Application,TRAFFIC-GEN Server,Average En +d-to-End Delay (s) = 0.020293675 1, ,[1024], Application,TRAFFIC-GEN Server,Average Ji +tter (s) = 0.056769093 1, ,[1024], Application,TRAFFIC-GEN Server,Client Add +ress = 192.0.0.5 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +art Time (s) = 0.058634166 1, ,[1024], Application,TRAFFIC-GEN Server,Session En +d Time (s) = 19.798208565 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +atus = Closed 1, ,[1024], Application,TRAFFIC-GEN Server,Total byte +s Received = 6624 1, ,[1024], Application,TRAFFIC-GEN Server,Total Data + Units Received = 207 1, ,[1024], Application,TRAFFIC-GEN Server,Throughput + (bits/s) = 2684 1, ,[1024], Application,TRAFFIC-GEN Server,Average En +d-to-End Delay (s) = 0.026288118 1, ,[1024], Application,TRAFFIC-GEN Server,Average Ji +tter (s) = 0.090685171 1, ,[1024], Application,TRAFFIC-GEN Server,Client Add +ress = 192.0.0.2 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +art Time (s) = 0.028508654 1, ,[1024], Application,TRAFFIC-GEN Server,Session En +d Time (s) = 19.981800333 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +atus = Closed 1, ,[1024], Application,TRAFFIC-GEN Server,Total byte +s Received = 12832 1, ,[1024], Application,TRAFFIC-GEN Server,Total Data + Units Received = 401 1, ,[1024], Application,TRAFFIC-GEN Server,Throughput + (bits/s) = 5144 1, ,[1024], Application,TRAFFIC-GEN Server,Average En +d-to-End Delay (s) = 0.009312223 1, ,[1024], Application,TRAFFIC-GEN Server,Average Ji +tter (s) = 0.046495978 1, ,[1024], Application,TRAFFIC-GEN Server,Client Add +ress = 192.0.0.3 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +art Time (s) = 0.017999448 1, ,[1024], Application,TRAFFIC-GEN Server,Session En +d Time (s) = 19.943126887 1, ,[1024], Application,TRAFFIC-GEN Server,Session St +atus = Closed 1, ,[1024], Application,TRAFFIC-GEN Server,Total byte +s Received = 10880 1, ,[1024], Application,TRAFFIC-GEN Server,Total Data + Units Received = 340 1, ,[1024], Application,TRAFFIC-GEN Server,Throughput + (bits/s) = 4368 1, ,[1024], Application,TRAFFIC-GEN Server,Average En +d-to-End Delay (s) = 0.019138684 1, ,[1024], Application,TRAFFIC-GEN Server,Average Ji +tter (s) = 0.060386082 2, , [0], Physical, 802_15_4,Signals transmitte +d = 1571 2, , [0], Physical, 802_15_4,Signals detected = + 1732 2, , [0], Physical, 802_15_4,Signals locked on +by PHY = 1191 </readmore> <code>
From this data file i need to extract the client address 192.168.0.(\d+) and the corresponding data units received. I tried the follwing:
open(STATFILE,$statfile) or die ("could not open the stat file"); my $lines = do { local $/; <STATFILE> }; my @ones; my @twos; while($lines =~ m/traffic-gen.*client address = 192\.0\.0\.(\d+).* +data units received = (\d+).*jitter/scgi) { print $1, "\tyes\t",$2,"\n"; push @ones, $1; push @twos, $2; } print @ones,@twos;
but it is printing only that last addresses and the corresponding data packets received: that is 3 and 340. I am new to regular expressions and perl in general. Kindly help ! Thanks in advance :)

In reply to multiple regexp matches in multi line string by wirelesscharlie

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.