I don't understand why you are using the $whileloop variable. Perl
has perfectly good loop control mechanisms. A quick rewrite would be
I think I used it because at first I tried while ($sock) - and that
didn't work. So I just used something I 'knew' would always hold true.
while (1) {
if ($sock) {
printf "Socket connected\n";
printf "$counter\n";
$counter++;
sleep 2;
} else {
last;
}
}
But why have two conditions in the first place? Also, why are you
using printf? You aren't doing any formating.
I forgot I could just use print
For that matter why do
you have two print statements when you only need one.
You're right, but does it slowdown the script much if if there are two?
I only ask because I didn't think about combining them into one line -
not questioning your perl know-how.
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my $counter = 1;
#don't use "new class", use "class->new"
my $sock = IO::Socket::INET->new(
PeerAddr => '10.5.7.33',
PeerPort => '21',
Proto => 'tcp',
) or die "Could not create socket: $!\n";
while ($sock->connected) {
print "Socket connected\n$counter\n";
$counter++;
sleep 2;
}
$sock->close;
print "Socket closed\n";
Still isn't working though. If I put the server interfaces down, then
of course it fails with the "Could not create socket: $!\n". However,
if I start the script with the server interface active it starts to
iterate through the loop. But if I then take the server interface down
it still iterates through, counting up and printing "Socket connected".
What am I missing here?
Matt
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/