range operators
( categories: operators )The range operators are .. (two dots) and ... (three dots).
In list context both operators behave in the same way, returning a list of values counting from the left value to the right value (it even works on strings).
They're very useful for creating loops, slicing arrays, etc.
Example:
printf "Line %d\n", ++$i foreach ( 1 .. 10 );
In scalar context, they emulate the behaviour of the line range operator of sed.
To do this, the operator returns a boolean value, and this value is maintained across the duration of the routine that has the operator.
comparison operators
( categories: operators )You have to use different comparison operators, depending whether you want to compare arguments numerically or stringwise:
- numerical comparison operators
| == | returns true if both arguments are numerically equal |
| != | returns true if both arguments are numerically different |
| <=> | returns -1, 0, or 1 depending on whether the left argument is numerically less than, equal to, or greater than the right argument |
| < | returns true if left argument is numerically smaller than right argument |
| > | returns true if left argument is numerically bigger than right argument |
| <= | returns true if left argument is numerically smaller or equal than right argument |
| >= | returns true if left argument is numerically bigger or equal than right argument |
precedence of operators
( categories: operators )The list is ordered from highest precedence to lowest:
