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

Hi,

I want to create an if statement where 2 individual variables are matched before action is taken.

To clarify what I want to do, I run a series of tests in different internet browsers on different operating systems. I need to define in my script that when the variable $host matches "MAC" AND the variable $browser matches "Internet Explorer", the script needs to skip the tests because IE does not run on MAC. My first thoughts are it would look something like this:

if ($host =~ /mac/, $browser eq "iexplore") { # skip tests; } else { # run tests as normal; }

I think the above statement is actually an if / or statement though.

Any help would be much appreciated.

Replies are listed 'Best First'.
Re: Help with IF statement for 2 matching conditions.
by Athanasius (Archbishop) on Nov 26, 2012 at 13:22 UTC

    Sounds like you’re looking for logical AND, which is && (or its lower-precedence version and):

    if ($host =~ /mac/ && $browser eq 'iexplore') { ...

    Hope that helps,

    Athanasius <°(((><contra mundum

      Wow what quick responses! Thanks a lot. I thought it must have been something simple but I couldn't find anything on the web, probably because I was searching for the wrong statement.

      Cheers!

        The building blocks in Perl are easy and powerful. With those blocks you can make very complex functionality.

        Good luck coding and automating the world!

Re: Help with IF statement for 2 matching conditions.
by McA (Priest) on Nov 26, 2012 at 13:21 UTC

    Hi

    the solution is in your own text:

    ... AND ...

    Best regards
    McA

    PS.: http://perldoc.perl.org/perlop.html#Logical-And

Re: Help with IF statement for 2 matching conditions.
by Anonymous Monk on Nov 26, 2012 at 21:42 UTC
    next if (($host =~ /mac/) && ($browser =~ /iexplore/));

    Don't get fancy-pants here ... be clear.
      There is nothing fancy or unclear about and