Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have been assigned a task to:
Create a web application using any technology that accepts an email address and checks if the domain of the email address exists.
I can make code for that in Perl by splitting out the part before @ and storing domain name in a scalar variable and then ping the domain name and checking the reply. It will solve the problem. But the problem is that I can not make a web application. I do not know that much Perl. I do not know CGI. I have to make and deliver this web application within 72 hours. Let me know which thing should I learn? If you could provide me good resources then that would be very kind. Thank you!
Re: Creating a web application in Perl
by tobyink (Canon) on Jan 07, 2012 at 09:45 UTC
|
Pinging a domain name is not an especially good indicator - there are a number of scenarios where a domain name will not respond to pings, but can accept mail.
So don't ping the domain. Use a Perl module like Net::DNS::Resolver to look up an MX record for the host; if there is no MX record, then look for an A/AAAA/CNAME record; if you've still not found a matching DNS entry, then the domain name probably can't receive mail.
use Net::DNS::Resolver;
my $domain = 'example.com';
my $dns = Net::DNS::Resolver->new;
my $valid = $dns->query($domain, 'MX')
|| gethostbyname($domain);
printf(
"You could %s send mail to %s.\n",
($valid ? "maybe" : "not"),
$domain,
);
| [reply] [d/l] [select] |
|
On a sidenote: Even if you the MX entry is valid, the mailserver is reachable and you are even to validate the email address by sending one one those "click here to validate" links, you can't besure it will work for more than a few minutes. There are more and more of this one-time email-address services available to avoid SPAM and all these annoying "you have registered at our site a few years ago so we constantly bombard you with our 'newsletter'" thingies.
I'm currently teaching my private mailservers how to do that onetime address thingy for the same reasons...
"Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid… and I went ahead anyway." (Crow in "MST3K The Movie")
| [reply] |
Re: Creating a web application in Perl
by planetscape (Chancellor) on Jan 07, 2012 at 08:58 UTC
|
| [reply] |
|
| [reply] |
Re: Creating a web application in Perl
by CountZero (Bishop) on Jan 07, 2012 at 10:32 UTC
|
Install Dancer and you are already half-way.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
|
My first reaction to this was that Dancer would be overkill for such a small task. I've been working with Dancer lately and like it a lot, but using a framework for what amounts to a 10-line CGI? But then I reconsidered and tried it. I can't say it saved me any time or lines of code, but it did keep things cleaner and more organized. The rule-based structure of Dancer makes it very easy to see what URI is involved. Keeping the code separate from the HTML makes it easier to write one and then the other, without the back-and-forth in my head that I tend to do when writing CGI with HTML embedded in it (as functions like h1() or as strings), which is nice even for a small task.
And since I already had Dancer running and configured on this site, I could just add the rule and the template, without worrying about the path to the perl executable, or whether my CGI needed to go in the cgi-bin directory or have a particular extension, or any of that other fun stuff that made installing CGI scripts too difficult for most newbies.
And if I want to expand on this utility later, to make it more robust by adding more logging and error checking, or perhaps to save the lookups in a database cache, the payoff from using Dancer in the first place will only grow as the complexity of the thing increases.
So I'm sold: Dancer is even good for small stuff. I probably still won't use it when I need to write a one-line script to run a one-time command on a server where I don't have shell access, like `rm annoying_file_owned_by_webserver_that_I_can't_remove_by_FTP`; those will still go in quick CGIs (or PHP). But I think everything else will be done in Dancer if it can be.
| [reply] [d/l] |
Re: Creating a web application in Perl
by JavaFan (Canon) on Jan 07, 2012 at 11:15 UTC
|
I have to make and deliver this web application within 72 hours. Let me know which thing should I learn?
Learn how to pray. And hope you pray to a entity that actually exists, and it is willing to perform some miracles for you.
| [reply] |
|
Papa Legba seems a good bet. In the Sprawl trilogy by William Gibson in the second book, Count Zero, Papa Legba stands at the gateway to cyberspace the "master of roads and pathways".
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
Re: Creating a web application in Perl
by TJPride (Pilgrim) on Jan 07, 2012 at 19:58 UTC
|
use CGI qw(:standard);
my $email = param('email');
CGI scripts also need to have their permissions changed so they can be run properly when accessed via something other than the command line. Generally speaking, this means changing to 755 (read, write, execute for owner, read and execute for group and all).
You may need to include the path to the Perl interpreter in the first line of the script. Maybe like so:
#!/usr/bin/perl
EDIT: And you need to print out a Content-Type before printing any other content:
print "Content-Type: text/html\n\n";
EDIT: One final note, you need to make dang sure that if you are using the command line to ping the domain (via backticks or whatever), you use regex to verify that nobody has inserted bad stuff into the email address, because otherwise they could essentially type all sorts of nasty stuff into the email and your script would run it for them. | [reply] [d/l] [select] |
Re: Creating a web application in Perl
by Anonymous Monk on Jan 07, 2012 at 08:26 UTC
|
| [reply] |
|
|