in reply to
Re: Timeout not working while reading from socket.
in thread Timeout not working while reading from socket.
I see what I did wrong..... THANKS.
This seems to work.
while (my $line = <$sock>)
{
if ($line =~ m/^(ALARM: )/)
{
timeout $nb_secs => sub
{
while (2)
{
$buf .= $sock->getline();
$sock->flush();
}
};
if ($@)
{
my $msg = MIME::Lite->new(
.......
Type =>'TEXT',
Data =>$buf ,
);
$msg->send();
print $file $buf;
$line = "";
$buf = "";
}
}
print $file $line; #Print current line to open $file.
}
}
sleep 10; # allow sometime to exit
close $file;