| ** | Exponentiation | |
| + - | * / | Addition, subtraction, multiplication, division |
| % | Modulo division | |
| & | | ^ | Bitwise AND, bitwise OR, bitwise exclusive OR |
| >> | << | Bitwise shift right, bitwise shift left |
| || | && | Logical OR, logical AND |
| . | Concatenation of two strings | |
| x | Returns a string or array consisting of the left operand (an array or a string) repeated the number of times specified by the right operand | |
| All of the above operators also have an assignment operator, e.g., .= | ||
| -> | Dereference operator | |
| \ | Reference (unary) | |
| ! | ~ | Negation (unary), bitwise complement (unary) |
| ++ | -- | Auto-increment (magical on strings), auto-decrement |
| == | != | Numeric equality, inequality |
| eq | ne | String equality, inequality |
| < | > | Numeric less than, greater than |
| lt | gt | String less than, greater than |
| <= | >= | Numeric less (greater) than or equal to |
| le | ge | String less (greater) than or equal to |
| <=> | cmp | Numeric (string) compare. Returns -1, 0, 1. |
| =~ | !~ | Search pattern, substitution, or translation (negated) |
| .. | Range (scalar context) or enumeration (array context) | |
| ?: | Alternation (if-then-else) operator | |
| , | Comma operator, also list element separator. You can also use =>. | |
| not | Low-precedence negation | |
| and | Low-precedence AND | |
| or | xor | Low-precedence OR, exclusive OR |
| . | Concatenation of two strings. |
| .= | The concatenation assignment operator. |
| eq | String equality (== is numeric equality). For a mnemonic just use "eq" as a string. |
| ne | String inequality (!= is numeric inequality). |
| lt | String less than. |
| gt | String greater than. |
| le | String less than or equal. |
| ge | String greater than or equal. |
| cmp | String comparison, returning -1, 0, or 1. |
| <=> | Numeric comparison, returning -1, 0, or 1. |
| =~ | Regular expression match. |
| !~ | Regular expression non-match, like =~ except the return value is negated. |
| x | The repetition operator. Returns a string consisting of the left operand repeated the number of times specified by the right operand. (In an array context, if the left operand is a list in parens, it repeats the list.) |
Examples:
$sa = "hallo "; $sb = "you!"; $sc = $sa . $sb; print "$sc\n"; $sc = $sa x 3 . $sb; print "$sc\n"; $sc = $sa le $sb; print "$sc\n";
String Functions
Examples:
$s = "this line\n\n"; print "$s x-lines further down"; print "\n\n\n"; chomp $s; print "$s x-lines further down"; print "\n\n\n"; chomp $s; chomp $s; chomp $s; print "$s x-lines further down"; print "\n\n\n";Output:
this line x-lines further down this line x-lines further down this line x-lines further down
@days[3..5] = qw/Wed Thu Fri/;
Examples:
@animals = ("camel", "llama", "owl");
push( @animals, ("you","me\n","next line") );
print "@animals";
print "\n";
chomp( @animals );
print "@animals";
Output:
camel llama owl you me next line camel llama owl you me next line
Examples:
camel owl llama yellow white sand owl llama white sand