From ae3f739188e3ee21fa593cafc28023c533e8d9bf Mon Sep 17 00:00:00 2001 From: Moritz Lenz Date: Sun, 21 Apr 2013 16:11:06 +0200 Subject: [PATCH] document that it is the operator that determines the operation In many other dynamic languages it is the operator plus the type of the first operand, so it is worth mentioning. --- pod/perlop.pod | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pod/perlop.pod b/pod/perlop.pod index 828b3a6..4c26fe7 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -5,6 +5,22 @@ perlop - Perl operators and precedence =head1 DESCRIPTION +In Perl, the operator determines what operation is performed, +independent of the type of the operands. For example C<$a + $b> +is always a numeric addition, and if C<$a> or C<$b> do not contain +numbers, an attempt is made to convert them to numbers first. + +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 has two versions of some operators, one for numeric +and one for string comparison. For example C<$a == $b> compares +two numbers for equality, and C<$a eq $b> compares two strings. + +There are a few exceptions though: C can be either string +repetition or list repetition, depending on the type of the left +operand, and C<&>, C<|> and C<^> can be either string or numeric bit +operations. + =head2 Operator Precedence and Associativity X X X -- 2.7.4