tcf03 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @hosts = qw/host1 host2 host3 pcbackup/; # my $net="myhost\.com"; # unused for now my $proto="icmp"; my $p = Net::Ping->new($proto); my @uphosts=(); my @downhosts=(); foreach my $host(@hosts) { if ($p->ping($host)) { push (@uphosts, $host); } else { push (@downhosts, $host); } } $p->close(); $#downhosts++; $#uphosts++; print "There are $#downhosts hosts down\n"; print "There are $#uphosts hosts alive\n\n"; print "The following hosts are alive: \n"; foreach my $item (@uphosts) { print "$item\n"; } print "\nThe following hosts are down: \n"; foreach my $item (@downhosts) { print "$item\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how is this uninitialized?
by dragonchild (Archbishop) on Dec 28, 2004 at 15:56 UTC | |
|
Re: how is this uninitialized?
by revdiablo (Prior) on Dec 28, 2004 at 18:11 UTC | |
by redlemon (Hermit) on Dec 29, 2004 at 14:10 UTC | |
|
Re: how is this uninitialized?
by blazar (Canon) on Dec 28, 2004 at 19:33 UTC |