perl crash on sucking $socket into array

I

imahacker

The following code has crashed every machine i have tried it on except
for the original one i wrote it on. (3 out of 4 boxes) All are freshly
formatted with activestate installed. The program is perl/tk if that
makes a diff. i have also bundled it with perl2exe, and it crashes in
the same way. The program just "stops responding."

I have isolated the problem to the @line=<$ocket> line. If i comment
this line out, the script works as expected, but this is undesirable.
I would like to have the mail transfer information stored in a var.
putting the @line=<$ocket> AFTER the close($ocket) also fixes the
problem, but perl warns me that I am trying to read a socket has
already been closed, and doesnt store the information. Any help or
pointers in the right direction would be greatly appreciated, as i am
fairly new to perl.

$hostmail="mail.domain.net";
chomp($hostmail);

@message='
This is my email message.
';

$ocket = IO::Socket::INET->new(
PeerAddr => "$hostmail",
PeerPort => "25") || die "could not connect to $host: $!\n";
print $ocket "delo domain.net\n";
print $ocket "MAIL FROM: me\@domain.net\n";
print $ocket "RCPT TO: addy\@domain.net\n";
print $ocket "DATA\n";
print $ocket 'From: "nickname" <[email protected]>';
print $ocket "\n";
print $ocket "To: <addy\@domain.net>\n";
print $ocket "Subject: subject here\n\n";
print $ocket "@message";
print $ocket "\n.\nQUIT\n";
close($ocket);
@line=<$ocket>;
print "@line";
 
A

A. Sinan Unur

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
I have isolated the problem to the @line=<$ocket> line.

See

perldoc -f shutdown
$hostmail="mail.domain.net";
chomp($hostmail);

@message='
This is my email message.
';

$ocket = IO::Socket::INET->new(
PeerAddr => "$hostmail",
PeerPort => "25") || die "could not connect to $host: $!\n";
print $ocket "delo domain.net\n";
print $ocket "MAIL FROM: me\@domain.net\n";
print $ocket "RCPT TO: addy\@domain.net\n";

Yuck!

See

http://search.cpan.org/~gbarr/libnet-1.19/Net/SMTP.pm
 
T

Tad McClellan

$hostmail="mail.domain.net";
chomp($hostmail);


Why attempt to remove a newline when it is not possible
that there even _is_ a newline?

@message='
This is my email message.
';

PeerAddr => "$hostmail",

perldoc -q vars

What's wrong with always quoting "$vars"?


So:

PeerAddr => $hostmail,
 
J

Joe Smith

I have isolated the problem to the @line=<$ocket> line.

That line should not be used. For interactive servers like SMTP,
you should read one line from the socket for each line you send.
You should not send the next line until you have verified that
the server did not present you with an error code.
Net::SMTP does that.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top