0
use strict;
use warnings;
use IO::Socket;

my $sock = new IO::Socket::INET(
									PeerAddr=> 'localhost',
									PeerPort=> '7070',
									Proto => 'tcp');

die "Could not create socket: $!\n" unless $sock;

my $run = "yes";
while($run eq "yes")
{

my $text = <STDIN>;
print $sock "$text";
print "Send more strings? yes/no";
$run = <STDIN>;
}
close($sock);

i have an while loop so that the script keeps running and you can enter text again for sending but i wont work why?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by d5e5
0

Your loop runs while($run eq "yes") but when the user enters yes at the prompt then $run contains yes with a newline character at the end. Try doing a chomp on the $run after assigning the STDIN to it.

print "Send more strings? yes/no";
$run = <STDIN>;
chomp($run);#Remove the newline character from input
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.