in reply to Array Woes
Since $sock is either defined or not, there's no real need for a $connected variable. Likewise, in the interest of reducing global variable propagation, it's better to pass $port explicitly.#!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; my @host = qw[ 192.168.1.3 192.168.46.2 ]; my $port = 22; foreach (@host) { check($_, $port); } sub check { my ($ip, $port) = @_; my $sock = IO::Socket::INET->new( PeerAddr => $ip, PeerPort => $port, Proto => 'tcp', timeout => 10, ); if ($sock) { print "$ip is listening on port $port\n"; return 1; } print "$ip is NOT listening on port $port.\n"; return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using 'and'
by LAI (Hermit) on Dec 12, 2002 at 22:13 UTC | |
by tadman (Prior) on Dec 12, 2002 at 22:20 UTC | |
by agentv (Friar) on Dec 12, 2002 at 23:50 UTC | |
by LAI (Hermit) on Dec 13, 2002 at 14:50 UTC | |
by tadman (Prior) on Dec 13, 2002 at 18:00 UTC | |
by agentv (Friar) on Dec 12, 2002 at 23:48 UTC |