> I realized that, out of all of the PERL code Ive written, Ive only been
> able to assign to a variable from a pattern match within an IF statement:
> 
> if ( /^From:(.*)$/ )
> {
>         $From = $1;
> }
> 
> Simple enough.  But now I wanted to go deeper and capture only the
> email address.
> 
> Problem is:
>               $from_ = $From =~ /@/;
> returns 1.

if((my $from_= $From) =~ /@/) {
    print "$from_ (which is now a copy of $From) has an at in it\n";
}

if (my ($from_) = $From =~ /^([EMAIL PROTECTED])$/ ) {
    print "$from_ looks passes a na�ve test for email address";
}

> 
> I didnt want the return status.  In this example I wanted @
> And I didnt want to use another IF statement
>               if ( $From =~ /(@)/ )
>               {
>                      $from_ = $1;
>               }
> 

There is no way to get around the IF statement (or it's moral
equivalent) because there are two separate things happening - the
assignment of the match , and the test to see if such assignment
occured.  

You could do something like:

my ($from_) = $From =~ /^From:\s+(.*)$/;
# here $from_ is either your match or undef

Which just allows you to defer the test for undef until later.

print "I saw an email address $from_\n" if defined($from_);

I just wrote about this a mere two weeks ago in this very forum.

http://www.nntp.perl.org/group/perl.beginners/70671


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to