http://qs321.pair.com?node_id=252644


in reply to My Code Is Functional...But Not Tidy :(

Here's how I would do it. YMMV.

#!/usr/bin/perl -w use strict; use IO::Socket::INET; my %services = ( pop => [ 'mail.test.com', 110 ], smtp => [ 'mail.test.com', 25 ], web => [ 'test.com', 80 ], dns => [ 'test.com', 53 ], ); my %status; $status{$_} = 'Up' for keys %services; while (my ($name,$svc) = each %services) { my $sock = IO::Socket::INET->new(Timeout=>1, PeerAddr => $svc->[0], PeerPort => $svc->[1], Proto => 'tcp' ) or $status{$name} = 'Down'; } while (my ($name,$sts) = each %status) { print "$name server is $sts\n"; }
90% of every Perl application is already written.
dragonchild