Assuming from your host_array that you're looking at websites, I also gather that you're interested if the web services are available. Since, as has been previously described, ping services are not always available, and ping doesn't really answer the question "Is the website accessible?", I'd recommend attempting a connection to port 80 on each box, which would at least tell you that
something (hopefully a webserver) is listening.
Here's the code:
#!/usr/bin/perl -w
use strict; # always
use Socket;
my @host_array = qw( www.slashdot.org www.deja.com www.perlmonks.org
+);
my $proto = 'tcp';
my $port = 80;
foreach my $host (@host_array) {
# open the socket
socket(SOCK,
PF_INET,
SOCK_STREAM,
getprotobyname($proto)) or die "Unable to create socket!\n";
# connect to remote site
my $isUp = connect(SOCK,
sockaddr_in($port,
inet_aton($host)));
# print what we found out
print "$host is ";
print "NOT " unless $isUp;
print "reachable.\n";
}
Cheers,
Shendal