architecture. So for example, C<~"\x{3B1}"> is C<"\x{FFFF_FC4E}"> on
32-bit machines and C<"\x{FFFF_FFFF_FFFF_FC4E}"> on 64-bit machines.
+If the experimental "bitwise" feature is enabled via C<use feature
+'bitwise'>, then unary "~" always treats its argument as a number, and an
+alternate form of the operator, "~.", always treats its argument as a
+string. So C<~0> and C<~"0"> will both give 2**32-1 on 32-bit platforms,
+whereas C<~.0> and C<~."0"> will both yield C<"\xff">. This feature
+produces a warning unless you use C<no warnings 'experimental::bitwise'>.
+
Unary "+" has no effect whatsoever, even on strings. It is useful
syntactically for separating a function name from a parenthesized expression
that would otherwise be interpreted as the complete list of function
print "Even\n" if ($x & 1) == 0;
+If the experimental "bitwise" feature is enabled via C<use feature
+'bitwise'>, then this operator always treats its operand as numbers. This
+feature produces a warning unless you use C<no warnings
+'experimental::bitwise'>.
+
=head2 Bitwise Or and Exclusive Or
X<operator, bitwise, or> X<bitwise or> X<|> X<operator, bitwise, xor>
X<bitwise xor> X<^>
print "false\n" if (8 | 2) != 10;
+If the experimental "bitwise" feature is enabled via C<use feature
+'bitwise'>, then this operator always treats its operand as numbers. This
+feature produces a warning unless you use C<no warnings
+'experimental::bitwise'>.
+
=head2 C-style Logical And
X<&&> X<logical and> X<operator, logical, and>
=head2 Assignment Operators
X<assignment> X<operator, assignment> X<=> X<**=> X<+=> X<*=> X<&=>
X<<< <<= >>> X<&&=> X<-=> X</=> X<|=> X<<< >>= >>> X<||=> X<//=> X<.=>
-X<%=> X<^=> X<x=>
+X<%=> X<^=> X<x=> X<&.=> X<|.=> X<^.=>
"=" is the ordinary assignment operator.
might trigger, such as from tie(). Other assignment operators work similarly.
The following are recognized:
- **= += *= &= <<= &&=
- -= /= |= >>= ||=
- .= %= ^= //=
+ **= += *= &= &.= <<= &&=
+ -= /= |= |.= >>= ||=
+ .= %= ^= ^.= //=
x=
Although these are grouped by family, they all have the precedence
the number of elements produced by the expression on the right hand
side of the assignment.
+The three dotted bitwise assignment operators (C<&.= |.= ^.=>) are new in
+Perl 5.22 and experimental. See L</Bitwise String Operators>.
+
=head2 Comma Operator
X<comma> X<operator, comma> X<,>
1 while foo();
=head2 Bitwise String Operators
-X<operator, bitwise, string>
+X<operator, bitwise, string> X<&.> X<|.> X<^.> X<~.>
Bitstrings of any size may be manipulated by the bitwise operators
(C<~ | & ^>).
$baz = 0+$foo & 0+$bar; # both ops explicitly numeric
$biz = "$foo" ^ "$bar"; # both ops explicitly stringy
+This somewhat unpredictable behavior can be avoided with the experimental
+"bitwise" feature, new in Perl 5.22. You can enable it via C<use feature
+'bitwise'>. By default, it will warn unless the "experimental::bitwise"
+warnings category has been disabled. (C<use experimental 'bitwise'> will
+enable the feature and disable the warning.) Under this feature, the four
+standard bitwise operators (C<~ | & ^>) are always numeric. Adding a dot
+after each operator (C<~. |. &. ^.>) forces it to treat its operands as
+strings:
+
+ use experimental "bitwise";
+ $foo = 150 | 105; # yields 255 (0x96 | 0x69 is 0xFF)
+ $foo = '150' | 105; # yields 255
+ $foo = 150 | '105'; # yields 255
+ $foo = '150' | '105'; # yields 255
+ $foo = 150 |. 105; # yields string '155' (under ASCII)
+ $foo = '150' |. 105; # yields string '155'
+ $foo = 150 |.'105'; # yields string '155'
+ $foo = '150' |.'105'; # yields string '155'
+
+ $baz = $foo & $bar; # both operands numeric
+ $biz = $foo ^. $bar; # both operands stringy
+
+The assignment variants of these operators (C<&= |= ^= &.= |.= ^.=>)
+behave likewise under the feature.
+
See L<perlfunc/vec> for information on how to manipulate individual bits
in a bit vector.