yam has asked for the wisdom of the Perl Monks concerning the following question:
This, on the other hand, doesn't work:# this code works # loop.pl > loop.txt has > 0 bytes use Net::Ping; my $adr = "192.168."; my @net = qw / 97. 100. 102. 104. 105. 32. 33. 34. /; my ($i, $j, $host); for ($i=0; $i<=7; $i++) { HOST: for ($j=16; $j<=250; $j++) { $host = $adr . $net[$i] . $j; print "$host\n"; } }
The HOST tag is for a jump that happens in the else clause. The output from the second script is like thus:use Net::Ping; my $adr = "192.168."; my @net = qw / 97. 100. 102. 104. 105. 32. 33. 34. /; my ($i, $j, $host); $p = Net::Ping->new() or die "Can't create ping object: $!\n"; for ($i=0; $i<=7; $i++) { HOST: for ($j=16; $j<=250; $j++) { $host = $adr . $net[$i] . $j; if (!$p->ping($host)) { print "$host not responding!\n"; next HOST; } else { print "$host\n"; } } }
192.168.97.16 192.168.97.17 192.168.97.18 192.168.97.19 192.168.97.20 192.168.97.21 192.168.97.22 192.168.97.23 192.168.97.24 192.168.97.25 192.168.97.26 not responding! 192.168.97.27but when I do ./ploop.pl > ploop.txt, ploop.txt is a 0 byte file and if I open and write to file, still nothing gets written to it. I don't understand what is happening. Anyone have a clue? Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Ping and STDOUT
by sk (Curate) on Aug 04, 2005 at 16:16 UTC | |
|
Re: Net::Ping and STDOUT
by blazar (Canon) on Aug 04, 2005 at 16:09 UTC | |
by yam (Novice) on Aug 04, 2005 at 16:12 UTC | |
by blazar (Canon) on Aug 04, 2005 at 16:24 UTC | |
by yam (Novice) on Aug 04, 2005 at 17:18 UTC | |
by yam (Novice) on Aug 04, 2005 at 17:25 UTC | |
by blazar (Canon) on Aug 04, 2005 at 17:45 UTC |