why isn't this working (perl Question)

David A. Sinck plug-discuss@lists.PLUG.phoenix.az.us
Sun, 22 Apr 2001 17:39:31 -0700


\_ 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