What does the ^ = operator do in Perl?

I am looking in the documentation what the ^ = assigment operator does.

The only thing I can find so far:

Other assignment operators work in a similar way. The following are recognized:

  **=    +=    *=    &=    &.=    <<=    
   -=    /=    |=    |.=   >>=    ||=
   .=    %=    ^=    ^.=   //=    &&=

What is the result $c ^= $r;?

+4
source share
2 answers

Perl ^=uses syntactic sugarfor xor operator

$xor_sum = $xor_sum ^ $i;

can be rewritten as

$xor_sum ^= $i;
+9
source

Every time you see a Perl expression of a form:

$l op= $r;

It can be rewritten as:

$l = $l op $r;

(Well, I say “anytime,” but there are probably exceptions. There are always exceptions in Perl, but I can't think about it now.)

+3
source

Source: https://habr.com/ru/post/1676352/


All Articles