I have two Perl scripts, server.pl and client.pl, that will print output from the client on the server.
However when the end of the file is reached I have to ctrl-C to get the next prompt instead of it closing the file and moving on with the rest of the program.
How can I get it to move on without doing a ctrl-c?
client.pl
However when the end of the file is reached I have to ctrl-C to get the next prompt instead of it closing the file and moving on with the rest of the program.
How can I get it to move on without doing a ctrl-c?
client.pl
Code:
#!/usr/bin/perl
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => '7070',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
$data_file = "/tmp/file.dat";
open(DAT, "<$data_file") || die "Could not open file: $!\n";
for (;;) {
while (<DAT>) {
my $msg = $_;
chomp $msg;
print $sock "$msg\n";
}
sleep 1;
DAT->clearerr();
}
close(DAT);
close($sock);