Gossamer Forum
Home : General : Perl Programming :

Perl Conditional

Quote Reply
Perl Conditional
Hi-

I currently have the following code in one of my scripts:

$to = $link->{'Email'};

This sets $to equal to the value of the field 'Email'. I was trying to figure out how to modify this so that in the case where there is a value for the field 'Alt_Email', then it would set $to to this value instead of 'Email'.

Does anyone know how to add that condition to make this work? I was trying various combinations, but couldn't get it to work.

--Frank
Quote Reply
Re: [FrankM] Perl Conditional In reply to
if ($link->{'Alt_Email'}=~ /.+\@.+\..+/) {
$to = $link->{'Alt_Email'};
}
elsif ($link->{'Email'}=~ /.+\@.+\..+/) {
$to = $link->{'Email'};
}
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Perl Conditional In reply to
Smile Thanks! Worked perfectly.

--Frank
Quote Reply
Re: [FrankM] Perl Conditional In reply to
You could also try this:

$to = ($link->{'Alt_Email'} =~ /.+\@.+\..+/) ? $link->{'Alt_Email'} : $link->{'Email'};

Of course, this assumes that $link->{'Email'} matches the pattern.