Keep getting error with email validation script

G

Get Links

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
print "Good email: $email\n";
open (OUT, ">>$zfile") || die("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}

I keep getting an error message with this. It should print the message
name added or bad email and it does neither.. [Sat Nov 4 23:41:29 2006]
[error] [client 75.4.21.59] Premature end of script headers:
/home/mortgage/public_html/cgi-bin/list.cgi [Sat Nov 4 23:40:56 2006]

Can anyone tell me what the problem is here? I"m using a simple form to
send the 2 fields.

Thanks,

Scot
 
B

Brian Wakem

Get said:
#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html";


Should be print "Content-type: text/html\n\n";
 
M

Mumia W. (reading news)

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html";

It seems that you are done printing headers at this point in the
program, so you should complete the header above (by providing the
obligatory \n) and print another \n to signal the start of the HTTP
content. The above line should be changed to two lines:

print "Content-type: text/html\n"; # notice the \n
print "\n"; # This signals that the HTTP headers have ended
# and the HTTP body is starting.

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
print "Good email: $email\n";
open (OUT, ">>$zfile") || die("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}

I keep getting an error message with this. It should print the message
name added or bad email and it does neither.. [Sat Nov 4 23:41:29 2006]
[error] [client 75.4.21.59] Premature end of script headers:
/home/mortgage/public_html/cgi-bin/list.cgi [Sat Nov 4 23:40:56 2006]

Can anyone tell me what the problem is here? I"m using a simple form to
send the 2 fields.

Thanks,

Scot
 
T

Tad McClellan

Get Links said:
print "Content-type: text/html";
^^
^^

You mark the end of the headers with a blank line, so:

print "Content-type: text/html\n\n";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
print "Good email: $email\n";


Errr, you said you were going to be generating HTML, but that
doesn't look like HTML, so:

print "Content-type: text/plain\n\n";

instead then.

print OUT $firstname ."|" . $email . "|" . "\n";


Yuck!

print OUT "$firstname|$email|\n";
or
print OUT join '|', $firstname, $email, "\n";
 
D

Dr.Ruud

Tad McClellan schreef:
print OUT join '|', $firstname, $email, "\n";

Alternatives:

1. { local $, = '|' ;
print OUT $firstname, $email, "\n" ;
}

2. { local ($\, $,) = ("\n", '|') ;
print OUT $firstname, $email, q// ;
}

3. { local ($\, $") = ("\n", '|') ;
print OUT "@{[ $firstname, $email, q// ]}" ;
}

I tend to use #2 a lot, but with ($\, $,) set earlier.
 
R

Randal L. Schwartz

"Get" == Get Links <[email protected]> writes:

Get> if ($email
Get> =~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)

That's absolutely *not* a regex to match a "valid email address".
You are victim of the cargo-cult phenomenon of "cut n paste this from
somewhere else" which apparently *also* got it wrong.

To validate email addresses, see Email::Valid and Mail::RFC822::Address
in the CPAN. Both of them *compute* the "valid email regex" from
component rules. Here is the result of one of them:

$ perl -MMail::RFC822::Address -le 'print Mail::RFC822::Address::make_rfc822re()'
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:mad:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?: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?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:mad:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*)

Yes, if you're not using a regex that is at LEAST that complex, you are NOT
matching email addresses. Yes, I'm serious.

print "Just another Perl hacker,"; # the original
 
G

Get Links

Wow! Randall Schwartz! I'm honored!...I've read your books..
I tried your regex and got a boo boo.. It said pattern not terminated.
Where did I goof this up?

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";
if ($email =~m/(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\]
\000-\031]+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,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
\t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[(?:[^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
\t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*)
{
print "Good email: $email\n";

open (OUT, ">>$zfile") || die("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}
 
G

Get Links

I just want to say thanks to everyone else for your help on this. I
got it working. I also want to check the dns to verify it also. I found
this code, but when I run it, it doesn't print out any message or add
the address to the list. it just hangs there with a blank browser.

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
&valid_address($email);
#print "valid email$valid";
#exit;
if ($valid==1) {
print "Good email: $email\n";
open (OUT, ">>$zfile") || die ("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}
}
sub valid_address {
my($addr) = @_;
my($domain, $valid);
return(0) unless ($addr =~ /^[^@]+@([-\w]+\.)+[A-Za-z]
{2,4}$/);
$domain = (split(/@/, $addr))[1];
$valid = 0; open(DNS, "nslookup -q=any $domain |") ||
return(-1);
while (<DNS>) {
$valid = 1 if (/^$domain.*\s(mail exchanger|
internet address)\s=/);
}
return($valid);
}


Thanks,

Scot

http://www.link-exchangers.com
"Get your page rank high"
 
G

grocery_stocker

Get said:
I just want to say thanks to everyone else for your help on this. I
got it working. I also want to check the dns to verify it also. I found
this code, but when I run it, it doesn't print out any message or add
the address to the list. it just hangs there with a blank browser.

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
&valid_address($email);
#print "valid email$valid";
#exit;
if ($valid==1) {
print "Good email: $email\n";
open (OUT, ">>$zfile") || die ("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}
}
sub valid_address {
my($addr) = @_;
my($domain, $valid);
return(0) unless ($addr =~ /^[^@]+@([-\w]+\.)+[A-Za-z]
{2,4}$/);
$domain = (split(/@/, $addr))[1];
$valid = 0; open(DNS, "nslookup -q=any $domain |") ||
return(-1);
while (<DNS>) {
$valid = 1 if (/^$domain.*\s(mail exchanger|
internet address)\s=/);
}
return($valid);
}


Thanks,

Scot

http://www.link-exchangers.com
"Get your page rank high"

I did something like this:
#!/usr/bin/perl
use warnings;

#test value;
my $email = "cdalten\@eecs\.berkeley\.edu";

valid_address($email);

#Yay, the price of nylons at walmart are now $5.07/pair. On top of it,
#they no longer carry the decent thigh highs.
sub valid_address{
my ($addr) = @_;
my ($domain, $name, $valid);
($name, $domain) = (split/@/,$addr);
$valid = 0;

#yes I know I should used fork()/exec;
system("nslookup $domain");
}

$./valid.pl
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 63.93.96.20
Address: 63.93.96.20#53

Non-authoritative answer:
Name: eecs.berkeley.edu
Address: 169.229.60.161
Name: eecs.berkeley.edu
Address: 169.229.60.27
 
G

grocery_stocker

grocery_stocker said:
Get said:
I just want to say thanks to everyone else for your help on this. I
got it working. I also want to check the dns to verify it also. I found
this code, but when I run it, it doesn't print out any message or add
the address to the list. it just hangs there with a blank browser.

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
&valid_address($email);
#print "valid email$valid";
#exit;
if ($valid==1) {
print "Good email: $email\n";
open (OUT, ">>$zfile") || die ("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}
}
sub valid_address {
my($addr) = @_;
my($domain, $valid);
return(0) unless ($addr =~ /^[^@]+@([-\w]+\.)+[A-Za-z]
{2,4}$/);
$domain = (split(/@/, $addr))[1];
$valid = 0; open(DNS, "nslookup -q=any $domain |") ||
return(-1);
while (<DNS>) {
$valid = 1 if (/^$domain.*\s(mail exchanger|
internet address)\s=/);
}
return($valid);
}


Thanks,

Scot

http://www.link-exchangers.com
"Get your page rank high"

I did something like this:
#!/usr/bin/perl
use warnings;

#test value;
my $email = "cdalten\@eecs\.berkeley\.edu";

valid_address($email);

#Yay, the price of nylons at walmart are now $5.07/pair. On top of it,
#they no longer carry the decent thigh highs.
sub valid_address{
my ($addr) = @_;
my ($domain, $name, $valid);
($name, $domain) = (split/@/,$addr);
$valid = 0;

#yes I know I should used fork()/exec;
system("nslookup $domain");
}

$./valid.pl
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 63.93.96.20
Address: 63.93.96.20#53

Non-authoritative answer:
Name: eecs.berkeley.edu
Address: 169.229.60.161
Name: eecs.berkeley.edu
Address: 169.229.60.27

This might upset some of the regulars, but I enjoy perl regular
expressions about as much as I enjoy hangovers.

Anyhow, couldn't we then modify the code to something like:
$valid = system("nslookup $domain");
return $valid;

Then go like:
my $test = valid_address($email);

if $test is zero, it's valid, otherwise it isn't.

I just ask this because I'm too lazy to read how fork() gets
implemented in Perl. The fact that $test captures the return value of
system() seems to indication the stuff is implemented differently. I
also figures since the OP is & to invoke the subroutine, we might as
well just continue to screw ourself by using the unsafe system()
function.
 
M

Mark Clements

Get said:
Wow! Randall Schwartz! I'm honored!...I've read your books..
I tried your regex and got a boo boo.. It said pattern not terminated.
Where did I goof this up?

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";
if ($email =~m/(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[

<snip>

You've missed Randal's point, or at least some of it. copy-and-paste is
not a sensible method of code reuse: use Email::Valid itself to do the
validation.

From the docs:

use Email::Valid;
print (Email::Valid->address('(e-mail address removed)') ? 'yes' :'no');

It's as simple as that.

Mark
 
P

Peter J. Holzer

Anyhow, couldn't we then modify the code to something like:
$valid = system("nslookup $domain");
return $valid;

Then go like:
my $test = valid_address($email);

No:

% nslookup hjp.at
Server: 127.0.0.1
Address: 127.0.0.1#53

*** Can't find hjp.at: No answer

However, <[email protected]> is a valid email address. You have to
check both MX and A records (and you would not use nslookup to this,
but the Net::DNS module). If you want to be thorough you can also
try to connect to the SMTP servers of the domain and ask them. There's a
module on CPAN which does this.
I just ask this because I'm too lazy to read how fork() gets
implemented in Perl.

What does fork have to do with the validity of email addresses?

hp
 
J

John W. Krahn

Get said:
I just want to say thanks to everyone else for your help on this. I
got it working. I also want to check the dns to verify it also. I found
this code, but when I run it, it doesn't print out any message or add
the address to the list. it just hangs there with a blank browser.

#!/usr/bin/perl -w

use CGI qw(param);
my $firstname = param("firstname");
my $email = param("email");
#my $email = "(e-mail address removed)";
my $zfile= "../list/list.txt";
#my $zfile= "c:/list.txt";
##########################################################
print "Content-type: text/html\n\n";

if ($email
=~m/^([A-Z0-9]+[._]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i)
{
&valid_address($email);
#print "valid email$valid";
#exit;
if ($valid==1) {
print "Good email: $email\n";
open (OUT, ">>$zfile") || die ("Can't open file!");
print OUT $firstname ."|" . $email . "|" . "\n";
close OUT;
print "name added";
} else {
print "Bad email: $email\n";
}
}
sub valid_address {
my($addr) = @_;
my($domain, $valid);
return(0) unless ($addr =~ /^[^@]+@([-\w]+\.)+[A-Za-z]
{2,4}$/);
$domain = (split(/@/, $addr))[1];
$valid = 0; open(DNS, "nslookup -q=any $domain |") ||
return(-1);
while (<DNS>) {
$valid = 1 if (/^$domain.*\s(mail exchanger|
internet address)\s=/);
}
return($valid);
}

You can use the Socket module to do DNS lookup:

$ perl -le'
use Socket;
my $host = q[link-exchangers.com];
my $address = inet_aton $host;
print inet_ntoa $address if $address;
'
216.227.212.185



John
 
G

grocery_stocker

Peter said:

I was grabbing for air at the time.
% nslookup hjp.at
Server: 127.0.0.1
Address: 127.0.0.1#53

*** Can't find hjp.at: No answer

However, <[email protected]> is a valid email address. You have to
check both MX and A records (and you would not use nslookup to this,
but the Net::DNS module). If you want to be thorough you can also
try to connect to the SMTP servers of the domain and ask them. There's a
module on CPAN which does this.

I was just going with the OP code of using nsloookup. It seemed like
the cool thing to do at
the time.
What does fork have to do with the validity of email addresses?

I honestly forgot. Maybe if the email addy gets revoked, would could
say "stick a fork in old email addy because it's been rendered inept".
 
T

Tad McClellan

grocery_stocker said:
I
also figures since the OP is & to invoke the subroutine,


What effect does using & on the function call have for the
function that is being discussed?

we might as
well just continue to screw ourself by using the unsafe system()
function.


What is unsafe about the system() function?

Using the shell is certainly unsafe, but you can use the system()
function in such a way that it won't use a shell.

Is that what you meant?
 
G

grocery_stocker

Tad said:
What effect does using & on the function call have for the
function that is being discussed?

I forgot. I think it was something to do with the fact the OP was
already screwing himself using &..
What is unsafe about the system() function?

Using the shell is certainly unsafe, but you can use the system()
function in such a way that it won't use a shell.

Is that what you meant?

I should probably explore this before I shoot off my mouth, but under
*nix, you can screw yourself with system() by having the user do
something really inane with the input. Like

char arr[200];
system(arr);

The user then can go like
ls -al; rm

This is because system() under *nix uses the fork/exec model. So is the
behavior different using Perl?
 
T

Tad McClellan

grocery_stocker said:
I forgot. I think it was something to do with the fact the OP was
already screwing himself using &..


How was using & screwing him up?

His code will work perfectly fine with an ampersand on the function call.

I should probably explore this before I shoot off my mouth,


That would be uncharacteristic of what I have observed of
your posts to this point.

but under
*nix, you can screw yourself with system() by having the user do
something really inane with the input. Like

char arr[200];
system(arr);

The user then can go like
ls -al; rm

This is because system() under *nix uses the fork/exec model.


No it isn't.

It is because there is a shell involved. (semicolon is a shell metacharacter.)

If you use the form of system() that does not invoke a shell,
then the above bad guy trick will not "work".

So is the
behavior different using Perl?


Perl's system() also uses the fork/exec model.

But that model is not the reason for the unsafety that you claim.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top