Hey Guys
I'm trying to read an answer from an SMTP server via socket.
I'm writing a function wich returns everything till it finds a line which
doesn't begin with 3 digits and a - (/^[\d]{3}-/), but returns this
line,too.
Best I could get till now, is the function below. My question now is, if
that one is good or anybody knows a better solution.(but no Net::SMTP
package or so pls)
I read somewhere that if I use select, i shouldn't use the "readline" with
<FH>, but with sysread() it gets much more complicated I guess...
Thanks
R.B.
Here's the code:
sub getSMTPResponse {
my ($sock) = @_;
my ($rin, $response, $i);
my ($timeout) = 5;
vec($rin="", fileno($sock), 1) = 1 ; # create bitmask with the socket
if (select($rin, undef, undef, $timeout)) { # check if socket is ready
do {
$i = <SOCK>; # read in a line
$response .= $i; # append to result
} while($i =~ /^[\d]{3}-/);
return($response); # return result
} else {
return(undef); # timeout on select occurred
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>