
In two's complement architectures, to get the opposite of a number, all you need to do is flip all bits, and add 1.

This golfing technique allows to get rid of a pair of parentheses: $y = ~-$x * 4 # identical to $y = ($x-1)*4 To get the inchworms on a stick to work on all signed integers, they must be used under the scope of use integer, so that signed integers are used everywhere in bitwise operations. It's actually even more limited by default: ~- only decrements integers greater than 0, and -~ only increments integers lesser than 0. For example, the relational operators in this section and the equality operators in the next one return 1 for true and a special version of the defined empty string, '', which counts as a zero but is exempt from warnings about improper numeric conversions, just as '0 but true' is. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. They increase and decrease respectively the value of a scalar variable by 1. Perl also provides ++ the auto increment, and -auto decrement operators.

Due to how ~ is implemented in Perl (a little known fact is that Perl's bitwise operators cast operands to unsigned integers without use integer and to signed integers with use integer), this pair of secret operators is limited to signed integers. Perl operators that return true or false generally return values that can be safely used as numbers. (We don't repeat the name of VARIABLE.) You can use it with any binary operator: +,, -, /, even (binary operators work on two values.) Auto increment and auto decrement. In C, Python and Ruby, they work on all integers. The arithmetic operators +, -,, and / The comparison operator The assignment operator Today, you learn about the rest of the operators that Perl. It's a trick that assembly language programmers have been using for decades. These two operators perform a high-precedence decrement ( ~-) and high-precedence increment ( -~) on integers (on a two's-complement architecture). Perl secret operators: Operator Nickname Function Perlsecret - Perl secret operators and constants SYNOPSIS
