Okay. So here is how I would do it:
use strict; my (%result); # Example lines searched for # 4 packets transmitted, 4 packets received, 0% packet loss # round-trip min/avg/max/mdev = 89.483/99.807/119.926/12.344 ms while (<DATA>) { SWITCH: { /transmitted/ && do { # This will "eat up" all "packets"-information $result{$2}=$1 while /(\d+)\s+packets\s+(\S+)/ +g; last SWITCH; }; /round-trip/ && do { # this will find all values seperated by / # and will store them under their key /(\S+)\s*=\s*(\S+)/; @result{split m(/),$1}= split m(/),$2; last SWITCH; }; } } # Your %result-keys depend on the output of ping print $result{'transmitted'}-$result{'received'}," packet(s) lost\n"; print $result{'avg'}," average\n"; print Dumper(\%result); __END__ PING dslreports.com (209.123.109.175) from 10.0.1.1 : 56(84) bytes of +data. 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=0 ttl=51 +time=89.483 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=1 ttl=51 +time=119.926 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=2 ttl=51 +time=89.899 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=3 ttl=51 +time=99.920 msec --- dslreports.com ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max/mdev = 89.483/99.807/119.926/12.344 ms
Example output:
0 packet(s) lost 99.807 average $VAR1 = { 'received,' => '4', 'avg' => '99.807', 'min' => '89.483', 'mdev' => '12.344', 'max' => '119.926', 'transmitted,' => '4' };

In reply to Re: Re: Re: MRTG script should be easy by Skeeve
in thread MRTG script should be easy by jalspach

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.