Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

The script below pings as expected, but it /never/, /ever/, prints anything. Why?
#!/usr/bin/perl use strict; use warnings; use Net::Ping; my $i = $ARGV[0] || -1; while(--$i){ my $p = Net::Ping->new(); my $host = int(rand(255)) . '.' . int(rand(255)) . '.' . int(r +and(255)) . '.' . int(rand(255)); $p->ping($host) and print "\n$host lives!\n"; $p->close(); print "."; }

Replies are listed 'Best First'.
Re: Ping loop doesn't print
by Joost (Canon) on Jun 01, 2007 at 21:10 UTC
Re: Ping loop doesn't print
by MidLifeXis (Monsignor) on Jun 01, 2007 at 21:08 UTC

    You need to either print to STDERR, or set STDOUT to non buffering.

    select(STDOUT); $|++;

    update: As far as never printing, much of the IP space is vacant, invalid, or unresponsive.

    --MidLifeXis

      Thanks.