DESCRIPTION In Perl, the operator determines what operation is performed, independent of the type of the operands. This is in contrast to many other dynamic languages, where the operation is determined by the type of the first argument. It also means that Perl best 60 second binary option platform two versions of some operators, one for numeric and one for string comparison.
Operator precedence means some operators are evaluated before others. Operator associativity defines what happens if a sequence of the same operators is used one after another: whether the evaluator will evaluate the left operations first, or the right first. Perl evaluates the expression left to right. Perl operators have the following associativity and precedence, listed from highest precedence to lowest. Operators borrowed from C keep the same precedence relationship with each other, even where C’s precedence is slightly screwy. This makes learning Perl easier for C folks.
With very few exceptions, these all operate on scalar values only, not array values. In the following sections, these operators are covered in detail, in the same order in which they appear in the table above. Many operators can be overloaded for objects. A TERM has the highest precedence in Perl.
They include variables, quote and quote-like operators, any expression in parentheses, and any function whose arguments are parenthesized. Actually, there aren’t really functions in this sense, just list operators and unary operators behaving as functions because you put parentheses around the arguments. In the absence of parentheses, the precedence of list operators such as print, sort, or chmod is either very high or very low depending on whether you are looking at the left side or the right side of the operator. In other words, list operators tend to gobble up all arguments that follow, and then act like a simple TERM with regard to the preceding expression. See Named Unary Operators for more discussion of this. Or technically speaking, a location capable of holding a hard reference, if it’s an array or hash reference being used for assignment. For the details of that feature, consult Postfix Dereference Syntax in perlref.
That is, if placed before a variable, they increment or decrement the variable by one before returning the value, and if placed after, increment or decrement after returning the value. Note that just as in C, Perl doesn’t define when the variable is incremented or decremented. You just know it will be done sometime before or after the value is returned. This also means that modifying a variable twice in the same statement will lead to undefined behavior. Perl will not guarantee what the result of the above statements is.
The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. The auto-decrement operator is not magical. Do not expect any particular results from these special cases, the results are platform-dependent.
If the operand is an identifier, a string consisting of a minus sign concatenated with the identifier is returned. Otherwise, if the string starts with a plus or minus, a string starting with the opposite sign is returned. Perl will attempt to convert the string to a numeric, and the arithmetic negation is performed. See also Integer Arithmetic and Bitwise String Operators.