Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: My Code Is Functional...But Not Tidy :(

by pfaut (Priest)
on Apr 23, 2003 at 17:47 UTC ( #252644=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://252644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-02-28 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?