why isn't this working (perl Question)

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: David A. Sinck
Date:  
Subject: why isn't this working (perl Question)

\_ SMTP quoth Kimbro Staken on 4/22/2001 16:08 as having spake thusly:
\_
\_ Try this
\_ 
\_ $bufr =~ /\<(.*\@.*)\>/;
\_ if ($1) {
\_    $email = $1;
\_ }


Ah, but this could lead to amusements if you fail to match on the
pattern and $1 is still 'good' from a previous match:


$bufr = "I love spam";
$bufr =~ /I love (\w+)/;

$buf =~ /<(.*@.*)>/;
if ($1)
  {
    print "What do I love: $1\n";
  }


Which is not what you want.

Try instead:

if ($bufr =~ /<\w+@\w+\.\w+>/)
{
    $email = $1;
# other logic for having detected valid email here
}


Notice the the regex is closer to enforcing a valid email, but still
does not guarantee it. For instance, it ignores local deliveries as
valid (sinck) and probably some other cases.

YMMV.


David, JAPH