William M West wrote:
> 
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
> 
> my $a = 1;
> my $b = 2;
> my $c = 2;
> my $d;
> 
> print "xor1" if ($a = $a) ^ ($b = $c);#prints
> 
> print "xor2" if ($a = $b) ^ ($b = $c);#no print
> 
> print "xor3" if ($a = $b) xor ($b = $c);#no print
> 
> print "xor4" if ($a = $a) xor ($b = $c);#no prints
> 
> print "xor5" if $a xor $b;#no prints
> 
> print "xor6" if $a xor $d;#prints
> 
> # so --- how do i use xor and ^ ???   i'd like to use it
> # for statements like the first few.... *sigh*
> #
> # i don't understand why the first one prints.... i really
> # need clarification on this one!


Perhaps this example will help:

$ perl -le'

for my $op ( "and", "or ", "xor" ) {
    print "0 $op 0 ", eval "0 $op 0" ? "TRUE" : "FALSE";
    print "0 $op 1 ", eval "0 $op 1" ? "TRUE" : "FALSE";
    print "1 $op 0 ", eval "1 $op 0" ? "TRUE" : "FALSE";
    print "1 $op 1 ", eval "1 $op 1" ? "TRUE" : "FALSE";
    }
'
0 and 0 FALSE
0 and 1 FALSE
1 and 0 FALSE
1 and 1 TRUE
0 or  0 FALSE
0 or  1 TRUE
1 or  0 TRUE
1 or  1 TRUE
0 xor 0 FALSE
0 xor 1 TRUE
1 xor 0 TRUE
1 xor 1 FALSE

Just replace any false value (undef, 0, '') for 0 and any true value for
1.  && and || work the same as and and or except that they have higher
precedence.  & and | and ^ are bit-wise operators.  At the bit level
they work the same as the example above.  If you use them on numbers or
strings they modify each bit of the number or string according to the
example above.

perldoc perlop


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to