almut, thanks for the idea. I have to admit, I am very wary of closing STDOUT, even if the job is running in cron.

In keeping with my offer, I tried a solution using Net::Ping, which, indeed, looks like exactly what I am looking for, as talexb mentioned.

Here are some preliminary results. I used

#some stuff like use strict, etc. Readonly my $udp_pinger => Net::Ping->new('udp',1); #other stuff, then beginning of loop my $t0 = [ gettimeofday() ]; `ping -q -w 1 -c 1 $host`; die if ($?); my $e0 = tv_interval($t0); print "Ping with backticks took $e0 seconds"; $t0 = [ gettimeofday() ]; $udp_pinger->ping($host) || die "udp ping failed for $host"; $e0 = tv_interval($t0); print "Ping with Net::Ping took $e0 seconds"; print ".."; #end of the loop
I put the return value checks in the timed segments to make the comparison as "fair" as possible. Also note that the program is a loop over 18 distinct hosts, not the same host repeatedly.

Results:

Ping with backticks took 0.004804 seconds
Ping with Net::Ping took 0.002682 seconds
..
Ping with backticks took 0.005873 seconds
Ping with Net::Ping took 0.001528 seconds
..
Ping with backticks took 0.005679 seconds
Ping with Net::Ping took 0.001115 seconds
..
Ping with backticks took 0.005465 seconds
Ping with Net::Ping took 0.001108 seconds
..
Ping with backticks took 0.005369 seconds
Ping with Net::Ping took 0.001098 seconds
..
Ping with backticks took 0.005465 seconds
Ping with Net::Ping took 0.001521 seconds
..
Ping with backticks took 0.006113 seconds
Ping with Net::Ping took 0.001071 seconds
..
Ping with backticks took 0.005269 seconds
Ping with Net::Ping took 0.001227 seconds
..
Ping with backticks took 0.005122 seconds
Ping with Net::Ping took 0.001262 seconds
..
Ping with backticks took 0.005421 seconds
Ping with Net::Ping took 0.00123 seconds
..
Ping with backticks took 0.00513 seconds
Ping with Net::Ping took 0.001106 seconds
..
Ping with backticks took 0.00501 seconds
Ping with Net::Ping took 0.001211 seconds
..
Ping with backticks took 0.005031 seconds
Ping with Net::Ping took 0.000958 seconds
..
Ping with backticks took 0.005107 seconds
Ping with Net::Ping took 0.001256 seconds
..
Ping with backticks took 0.005139 seconds
Ping with Net::Ping took 0.000981 seconds
..
Ping with backticks took 0.005484 seconds
Ping with Net::Ping took 0.001086 seconds
..
Ping with backticks took 0.003778 seconds
Ping with Net::Ping took 0.000643 seconds

Booyah! Knocks the socks off of what I had so far. I don't know what the overhead of using the module and/or instantiating the Net::Ping object are, so the comparison still isn't "fair" until you figure those and amortize them over the actual calls to ping(), but I am comfortable with the result being better than what I had. (And for more reasons than it just being faster)

Also, the data above are (IMO) a good representative sample, and one thing I have noticed is that the first call is always the slowest. I don't know what kind of optimization happens, but the second and later pings are (so far) always at least twice as fast as the first.

Finally, pretty convenient that 'backticks' and 'Net::Ping' have the same number of characters, eh?

I like computer programming because it's like Legos for the mind.

In reply to Re: I think I just found a good reason to use backticks in a void context. by OfficeLinebacker
in thread I thought I found a good reason to use backticks in a void context, but I was wrong. by OfficeLinebacker

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.