CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
turn on debug below perl code


New User

Mar 27, 2011, 9:12 PM

Post #1 of 2 (2650 views)
turn on debug below perl code Can't Post

How to turn on debug in fucntion sendSMTP??

What isthe function of var $DEBUG ??


#!/usr/bin/perl -w

use Socket;
use strict;

my($mailTo) = '';
my($mailServer) = '';

my($mailFrom) = '';
my($realName) = "chuikingman";
my($subject) = 'Test send_mail';
my($body) = "Test Line One.\nTest Line Two.\n";

$main::SIG{'INT'} = 'closeSocket';

my($proto) = getprotobyname("tcp") || 6;
my($port) = getservbyname("SMTP", "tcp") || 25;
my($serverAddr) = (gethostbyname($mailServer))[4];

die('gethostbyname failed.') unless (defined($serverAddr));

socket(SMTP, AF_INET(), SOCK_STREAM(), $proto)
or die("socket: $!");

my $packFormat;
$packFormat = 'S n a4 x8'; # Windows 95, SunOs 4.1+
#$packFormat = 'S n c4 x8'; # SunOs 5.4+ (Solaris 2)

connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr))
or die("connect: $!");

select(SMTP); $| = 1; select(STDOUT); # use unbuffered i/o.

my($inpBuf) = '';

recv(SMTP, $inpBuf, 200, 0);
recv(SMTP, $inpBuf, 200, 0);
my $debug = 1 ;
sendSMTP(1, "HELO\n");
sendSMTP(1, "MAIL From: <$mailFrom>\n");
sendSMTP(1, "RCPT To: <$mailTo>\n");
sendSMTP(1, "DATA\n");

send(SMTP, "From: $realName\n", 0);
send(SMTP, "Subject: $subject\n", 0);
send(SMTP, $body, 0);

sendSMTP(1, "\r\n.\r\n");
sendSMTP(1, "QUIT\n");


sub closeSocket { # close smtp socket on error
die("SMTP socket closed due to SIGINT\n");

sub sendSMTP {
my($debug) = shift;
#my($debug) = 1;
my($buffer) = @_;

print STDERR ("> $buffer") if $debug;
send(SMTP, $buffer, 0);

recv(SMTP, $buffer, 200, 0);
print STDERR ("< $buffer") if $debug;

return( (split(/ /, $buffer))[0] );


Mar 28, 2011, 9:13 AM

Post #2 of 2 (2643 views)
Re: [abcdef] turn on debug below perl code [In reply to] Can't Post

How to turn on debug in fucntion sendSMTP??

According to the code you supplied, you would pass a value evaluating to true as first argument to sendSMTP to enable debug output, and a value evaluating to false to disable it.

What isthe function of var $DEBUG ??

I can't see a variable of that name in your code. However, I see two variables named $debug.

BTW, although you obviously did not write the code yourself (otherwise you wouldn't ask these questions), I suggest that *if* you are going to use this code (and not just studying it), you also enable warnings.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives