>>>>> "APK" == Akhthar Parvez K <akht...@sysadminguide.com> writes:

  APK> There was a typo in my original email. I missed the word "not" which was 
very crucial as always.
  APK> Scenario: #1
  APK> unless ( (defined $result) && ($test !~ /TEST/) )

i recomment never using !~ as it doesn't read well and it makes for poor
boolean tests. also i rarely use unless for complex (2 or more) boolean
ops for the same reason.

  APK>  { my $result = "OK";
  APK>    print "$result\n";
  APK>  }
  APK> I thought it was:
  APK> UNLESS $result is defined and UNLESS $test does not contain TEST = IF 
$result is not defined and if $test contains TEST.

no, that is not boolean logic. the && happens first and then the unless
inverts that for the conditional test. a conditional is always only one
boolean value that must be derived from the expression. unless/if
doesn't see the multiple parts.

  APK> Scenario: #2
  APK> unless (defined $result)
  APK>  {
  APK>   unless ($test !~ /TEST/)
  APK>    { my $result = "OK";
  APK>      print "$result\n";
  APK>    }
  APK>  }
 
  APK> This would work as I thought (UNLESS $result is defined and
  APK> UNLESS $test does not contain TEST), but not the scenario #1.

that is two separate boolean tests so it works as you think it does. if
you inverted the earlier unless by applying demorgan's law it would look
like this:

if ( ! defined $result || $test =~ /TEST/ ) {

you can read it better and see what is really happening. if you don't
have a result OR the test is a TEST, then do this. use my boolean rules
above and you won't run into this confusion as much.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to