On Tue, Feb 11, 2003 at 03:16:32PM -0500, Bob Rogers wrote:

>    Also, I've attached a code fragment I wrote to validate email address
> syntax.

Thanks very much for the code sample and link to Bernstein's great RFC
822 info site.

I would like to point out that your code can be improved by replacing
uses of $& and $` with parentheses in the regexes followed by $1 and
$2.  This is from the Devel::SawAmpersand doc:

    *   never use $& and friends in a library.

    *   Don't "use English" in a library, because it contains the three bad
        fellows. Corollary: if you really want to use English, do it like
        so:

            use English qw( -no_match_vars ) ;

    *   before you release a module or program, check if sawampersand is set
        by any of the modules you use or require.

    Fortunately perl offers easy to use alternatives, that is

           instead of this              you can use this

         $`   of   /pattern/          $1   of  /(.*?)pattern/s
         $& of   /pattern/          $1   of  /(pattern)/
         $'   of   /pattern/          $+   of  /pattern(.*)/s

    In general, apply "/^(.*)(pattern)(.*)$/s" and use $1 for $`, $2
    for $& and $+ for $' ($+ is not dependent on the number of parens
    in the original pattern). Note that the "/s" switch can alter the
    meaning of "." in your pattern.

Best
-John

>     if ($component =~ /$rfc822_illegal_atom_character+/o) {
>       # one-based for the user, plus the local-part length for hosts.
>       my $bad_start = length($`)+$offset;
>       # [we'd like to get $bad_chars in the message.  but the only reliable
>       # way to avoid confusing the browser is to render them in hex, which the
>       # user is not likely to understand.  -- rgr, 14-Dec-98.]
>       my $bad_chars = $&;


>       elsif ($result =~ /\*\*\*.*/) {
>           # error message in MX retrieval; probably no such domain.
>           address_error
>               ("Our server cannot figure out how to send mail to <tt>&quot;"
>                . html_quotify($domain_name) . "&quot;</tt>.  Here is the "
>                . "error returned by the name server:\n<blockquote>"
>                . html_quotify($&)

-- 
John Tobey <[EMAIL PROTECTED]>
\____^-^
/\  /\
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to