Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm new to Perl, and I'm trying to use an 'if' statement, but it's not working. I want it to execute the block of code as long as $condition is not equal to "SN" and not equal to "SU". What is wrong with my code here? Thanks. :D
if !($condition eq "SN") && if !($condition eq "SU") { #Code }

Edit kudra, 2002-05-30 Added code tags

Replies are listed 'Best First'.
Re: New to Perl - Question about using &&
by broquaint (Abbot) on May 30, 2002 at 12:12 UTC
    Both conditions need to be in one set of parentheses e.g
    if($condition ne 'SN' && $condition ne 'SU') { ... } # of if you like your regexes if($condition !~ /^S[UN]$/) { ... }
    For more info on perl's syntax check out the perlsyn manpage.
    HTH

    _________
    broquaint

Re: New to Perl - Question about using &&
by LTjake (Prior) on May 30, 2002 at 12:12 UTC
    Hello,

    I would prefer to use:
    if (($condition ne 'SN') && ($condition ne 'SU')) { #Code }
    rather than using the bang before your paren. Also, I should note that you don't need to write the "if" part twice. As you can see by my code i use only one if(___) and inside those, bracket off each condition i'm checking.

    Cheers,
    -Brian

    Note: after reading broquaint's post, I too should have linked to perlsyn.
Re: New to Perl - Question about using &&
by Anonymous Monk on May 30, 2002 at 12:22 UTC
    Thank you very much for your help :D