in reply to Re: Re: Re: Re: Re: Ping and Tracert
in thread Ping and Tracert

This is running on Linux.
$ip = ''; $ping = `ping -c 3 $ip`; @times = $ping =~ /time=(\d+\.\d+)/; @times = sort { $b <=> $a } @times; print "High to low @times ms\n"; print "Highest $times[0] ms\n"; print "Lowest $times[-1] ms\n"; print "This was the reply parsed\n$ping\n";
And here are the results.
High to low 87.719 ms Highest 87.719 ms Lowest 87.719 ms This was the reply parsed PING ( from : 56(84) byte +s of data. 64 bytes from ( icmp_seq=0 ttl=2 +38 time=87.719 msec 64 bytes from ( icmp_seq=1 ttl=2 +38 time=81.823 msec 64 bytes from ( icmp_seq=2 ttl=2 +38 time=82.001 msec --- ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/mdev = 81.823/83.847/87.719/2.758 ms
It's not giving me the right data in the highest, lowest and highest to lowest. Please help.


qball~"I have node idea?!"

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Ping and Tracert
by tachyon (Chancellor) on Sep 01, 2001 at 00:30 UTC

    You have lost the /g off my regex when you modified it so you only match the first time=87.719 Thus the array only gets this one element. The /g makes it match all the time=nn.nnn and return them to the array. Make the regex @times = $ping =~ /time=(\d+\.\d+)/g; like it was and it will work fine. BTW if you use a char class like this /time=([\d\.]+)/g you are more flexible as you don't insist on the decimal point.