Kurt writes:
> if ($client ne $newclient and $method ne $newmethod){
> print "something\n"; #I'll actually be
> printing this to my report once I get this worked out
> }
>....
> Problem is that this seems to work for only the first set of variables and
> ignores the ones after the "and". For instance $method could be either
> CMD.EXE or ROOT.EXE. Any ideas? I added a line of code to show what the
> strings $newclient and $newmethod contain at each loop and it is correct, so
> I'm a little confused.
Several people suggested using the && operator instead of the 'and'
operator; I doubt this helped. The 'and' operator is just like the &&
operator, but at a lower precedence so you need not add extra
parentheses. The code you have is correct, but it might not be doing
what you want to be doing.
Your boolean condition will be true if $client is not equal to
$newclient and also $method is not equal to $newmethod. A simpler way
of saying that is: your boolean condition will be false unless $client
equals $newclient or $method equals $newmethod. The following short
script shows this to be the case:
#!/usr/bin/perl
use strict;
use warnings;
my $client = "client";
my $newclient = "client";
my $method = "method";
my $newmethod = "method";
if ($client ne $newclient and $method ne $newmethod) {
print "1 should NOT be printed - $client and $newclient are the same\n";
}
$newclient = "something else";
if ($client ne $newclient and $method ne $newmethod) {
print "2 should NOT be printed - $method and $newmethod are the same\n";
}
$newmethod = "something else";
if ($client ne $newclient and $method ne $newmethod) {
print "3 should be printed\n";
}
unless ($client eq $newclient or $method eq $newmethod) {
print "4 should be printed - this is identical to 3\n";
}
exit;
This correctly prints:
3 should be printed
4 should be printed - this is identical to 3
My guess is that you might want to be using the 'or' operator instead
of the 'and' operator:
if ($client ne $newclient or $method ne $newmethod) {
In this case, if either $client differs from $newclient or $method
differs from $newmethod, your condition will be true and the print
statement will run. Again, a simpler way of writing that is:
unless ($client eq $newclient and $method eq $newmethod) {
Another thing to notice is that perl only evaluates the minimum
necessary to reach a conclusion on the state of the boolean. For
'and' and &&, if the first part ($client ne $newclient) is false, the
whole condition must be false, so the second part ($method ne
$newmethod) is not evaluated. Similarly for 'or' and ||, if the first
part is true, the whole condition must be true, so the second part is
not evaluated.
+ Richard J. Barbalace
(a little behind on the list digests....)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]