How do I check a valid mail address?
$ perldoc -q check
You can't, at least, not in real time. Bummer, eh?
Without sending mail to the address and seeing whether
there's a human on the other hand to answer you, you can-
not determine whether a mail address is valid. Even if
you apply the mail header standard, you can have problems,
because there are deliverable addresses that aren't
RFC-822 (the mail header standard) compliant, and
addresses that aren't deliverable which are compliant.
Many are tempted to try to eliminate many frequently-
invalid mail addresses with a simple regex, such as
"/^[\w.-]+\@(?:[\w-]+\.)+\w+$/". It's a very bad idea.
However, this also throws out many valid ones, and says
nothing about potential deliverability, so it is not sug-
gested. Instead, see
http://www.perl.com/CPAN/authors/Tom_Chris-
tiansen/scripts/ckaddr.gz, which actually checks against
the full RFC spec (except for nested comments), looks for
addresses you may not wish to accept mail to (say, Bill
Clinton or your postmaster), and then makes sure that the
hostname given can be looked up in the DNS MX records.
It's not fast, but it works for what it tries to do.
Our best advice for verifying a person's mail address is
to have them enter their address twice, just as you nor-
mally do to change a password. This usually weeds out
typos. If both versions match, send mail to that address
with a personal message that looks somewhat like:
Dear someuser@host.com,
Please confirm the mail address you gave us Wed May 6 09:38:41
MDT 1998 by replying to this message. Include the string
"Rumpelstiltskin" in that reply, but spelled in reverse; that is,
start with "Nik...". Once this is done, your confirmed address will
be entered into our records.
If you get the message back and they've followed your
directions, you can be reasonably assured that it's real.
A related strategy that's less open to forgery is to give
them a PIN (personal ID number). Record the address and
PIN (best that it be a random one) for later processing.
In the mail you send, ask them to include the PIN in their
reply. But if it bounces, or the message is included via
a ``vacation'' script, it'll be there anyway. So it's
best to ask them to mail back a slight alteration of the
PIN, such as with the characters reversed, one added or
subtracted to each digit, etc.
Is there a pretty-printer (formatter) for Perl?
There is no program that will reformat Perl as much as
indent(1) does for C. The complex feedback between the
scanner and the parser (this feedback is what confuses the
vgrind and emacs programs) makes it challenging at best to
write a stand-alone Perl parser.
Of course, if you simply follow the guidelines in the
perlstyle manpage, you shouldn't need to reformat. The
habit of formatting your code as you write it will help
prevent bugs. Your editor can and should help you with
this. The perl-mode or newer cperl-mode for emacs can
provide remarkable amounts of help with most (but not all)
code, and even less programmable editors can provide sig
nificant assistance. Tom swears by the following settings
in vi and its clones:
set ai sw=4
map! ^O {^M}^[O^T
Now put that in your .exrc file (replacing the caret char
acters with control characters) and away you go. In
insert mode, ^T is for indenting, ^D is for undenting, and
^O is for blockdenting-- as it were. If you haven't used
the last one, you're missing a lot. A more complete exam
ple, with comments, can be found at
http://www.perl.com/CPAN-
local/authors/id/TOMC/scripts/toms.exrc.gz
If you are used to using the vgrind program for printing
out nice code to a laser printer, you can take a stab at
this using http://www.perl.com/CPAN/doc/misc/tips/work
ing.vgrind.entry, but the results are not particularly
satisfying for sophisticated code.
The a2ps at http://www.infres.enst.fr/%7Edemaille/a2ps/
does lots of things related to generating nicely printed
output of documents.
Simple check for a valid e-Mail address
/^[A-Z0-9\-_\.]+\@[A-Z0-9\-\.]+\.[A-Z]{2,}$/i