Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re: Re: Re: Re: Ping and Tracert

by qball (Beadle)
on Sep 01, 2001 at 00:18 UTC ( [id://109534]=note: print w/replies, xml ) Need Help??


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

This is running on Linux.
$ip = 'www.perlmonks.org'; $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 www.perlmonks.org (206.170.14.76) from 207.16.70.63 : 56(84) byte +s of data. 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=0 ttl=2 +38 time=87.719 msec 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=1 ttl=2 +38 time=81.823 msec 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=2 ttl=2 +38 time=82.001 msec --- www.perlmonks.org 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.

Thanks

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.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found