=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<x> 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<operator, precedence> X<precedence> X<associativity>
left || //
nonassoc .. ...
right ?:
- right = += -= *= etc.
+ right = += -= *= etc. goto last next redo dump
left , =>
nonassoc list operators (rightward)
right not
and the left side must be either an object (a blessed reference)
or a class name (that is, a package name). See L<perlobj>.
+The dereferencing cases (as opposed to method-calling cases) are
+somewhat extended by the experimental C<postderef> feature. For the
+details of that feature, consult L<perlref/Postfix Dereference Syntax>.
+
=head2 Auto-increment and Auto-decrement
X<increment> X<auto-increment> X<++> X<decrement> X<auto-decrement> X<-->
binary C<~~> does a "smartmatch" between its arguments. This is mostly
used implicitly in the C<when> construct described in L<perlsyn>, although
not all C<when> clauses call the smartmatch operator. Unique among all of
-Perl's operators, the smartmatch operator can recurse.
+Perl's operators, the smartmatch operator can recurse. The smartmatch
+operator is L<experimental|perlpolicy/experimental> and its behavior is
+subject to change.
It is also unique in that all other Perl operators impose a context
(usually string or numeric context) on their operands, autoconverting
like: exists HASH->{Any}
Right operand is CODE:
-
+
Left Right Description and pseudocode
===============================================================
ARRAY CODE sub returns true on all ARRAY elements[1]
=head2 Bitwise And
X<operator, bitwise, and> X<bitwise and> X<&>
-Binary "&" returns its operands ANDed together bit by bit.
-(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
+Binary "&" returns its operands ANDed together bit by bit. Although no
+warning is currently raised, the result is not well defined when this operation
+is performed on operands that aren't either numbers (see
+L<Integer Arithmetic>) or bitstrings (see L<Bitwise String Operators>).
Note that "&" has lower priority than relational operators, so for example
the parentheses are essential in a test like
X<bitwise xor> X<^>
Binary "|" returns its operands ORed together bit by bit.
-(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
Binary "^" returns its operands XORed together bit by bit.
-(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
+
+Although no warning is currently raised, the results are not well
+defined when these operations are performed on operands that aren't either
+numbers (see L<Integer Arithmetic>) or bitstrings (see L<Bitwise String
+Operators>).
Note that "|" and "^" have lower priority than relational operators, so
for example the brackets are essential in a test like
However, because there are I<many> other lowercase Greek characters than
just those, to match lowercase Greek characters in a regular expression,
-you would use the pattern C</(?:(?=\p{Greek})\p{Lower})+/>.
+you could use the pattern C</(?:(?=\p{Greek})\p{Lower})+/> (or the
+L<experimental feature|perlrecharclass/Extended Bracketed Character
+Classes> C<S</(?[ \p{Greek} & \p{Lower} ])+/>>).
Because each operand is evaluated in integer form, C<2.18 .. 3.14> will
return two elements in list context.
\c? chr(127)
In other words, it's the character whose code point has had 64 xor'd with
-its uppercase. C<\c?> is DELETE because C<ord("@") ^ 64> is 127, and
+its uppercase. C<\c?> is DELETE because C<ord("?") ^ 64> is 127, and
C<\c@> is NULL because the ord of "@" is 64, so xor'ing 64 itself produces 0.
Also, C<\c\I<X>> yields C< chr(28) . "I<X>"> for any I<X>, but cannot come at the
=back
B<NOTE>: Unlike C and other languages, Perl has no C<\v> escape sequence for
-the vertical tab (VT - ASCII 11), but you may use C<\ck> or C<\x0b>. (C<\v>
+the vertical tab (VT, which is 11 in both ASCII and EBCDIC), but you may
+use C<\ck> or
+C<\x0b>. (C<\v>
does have meaning in regular expression patterns in Perl, see L<perlre>.)
The following escape sequences are available in constructs that interpolate,
beyond) is being used, the case map used by C<\l>, C<\L>, C<\u>, and
C<\U> is as defined by Unicode. That means that case-mapping
a single character can sometimes produce several characters.
-Under C<use locale>, C<\F> produces the same results as C<\L>.
+Under C<use locale>, C<\F> produces the same results as C<\L>
+for all locales but a UTF-8 one, where it instead uses the Unicode
+definition.
All systems use the virtual C<"\n"> to represent a line terminator,
called a "newline". There is no such thing as an unvarying, physical
o Compile pattern only once.
a ASCII-restrict: Use ASCII for \d, \s, \w; specifying two
a's further restricts /i matching so that no ASCII
- character will match a non-ASCII one
- l Use the locale
- u Use Unicode rules
- d Use Unicode or native charset, as in 5.12 and earlier
+ character will match a non-ASCII one.
+ l Use the locale.
+ u Use Unicode rules.
+ d Use Unicode or native charset, as in 5.12 and earlier.
If a precompiled pattern is embedded in a larger pattern then the effect
of "msixpluad" will be propagated appropriately. The effect the "o"
explicitly using it.
The last four modifiers listed above, added in Perl 5.14,
-control the character set semantics, but C</a> is the only one you are likely
+control the character set rules, but C</a> is the only one you are likely
to want to specify explicitly; the other three are selected
automatically by various pragmas.
as delimiters. This is particularly useful for matching path names
that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is
the delimiter, then a match-only-once rule applies,
-described in C<m?PATTERN?> below.
-If "'" is the delimiter, no interpolation is performed on the PATTERN.
+described in C<m?PATTERN?> below. If "'" (single quote) is the delimiter,
+no interpolation is performed on the PATTERN.
When using a character valid in an identifier, whitespace is required
after the C<m>.
=item `STRING`
A string which is (possibly) interpolated and then executed as a
-system command with C</bin/sh> or its equivalent. Shell wildcards,
+system command with F</bin/sh> or its equivalent. Shell wildcards,
pipes, and redirections will be honored. The collected standard
output of the command is returned; standard error is unaffected. In
scalar context, it comes back as a single (potentially multi-line)
FINIS
If you use a here-doc within a delimited construct, such as in C<s///eg>,
-the quoted material must come on the lines following the final delimiter.
-So instead of
+the quoted material must still come on the line following the
+C<<< <<FOO >>> marker, which means it may be inside the delimited
+construct:
s/this/<<E . 'that'
the other
E
. 'more '/eg;
-you have to write
+It works this way as of Perl 5.18. Historically, it was inconsistent, and
+you would have to write
s/this/<<E . 'that'
. 'more '/eg;
the other
E
-If the terminating identifier is on the last line of the program, you
-must be sure there is a newline after it; otherwise, Perl will give the
-warning B<Can't find string terminator "END" anywhere before EOF...>.
+outside of string evals.
Additionally, quoting rules for the end-of-string identifier are
unrelated to Perl's quoting rules. C<q()>, C<qq()>, and the like are not
Let it be stressed that I<whatever falls between C<\Q> and C<\E>>
is interpolated in the usual way. Something like C<"\Q\\E"> has
-no C<\E> inside. instead, it has C<\Q>, C<\\>, and C<E>, so the
+no C<\E> inside. Instead, it has C<\Q>, C<\\>, and C<E>, so the
result is the same as for C<"\\\\E">. As a general rule, backslashes
between C<\Q> and C<\E> may lead to counterintuitive results. So,
C<"\Q\t\E"> is converted to C<quotemeta("\t")>, which is the same
Here is a short, but incomplete summary:
- Math::Fraction big, unlimited fractions like 9973 / 12967
Math::String treat string sequences like numbers
Math::FixedPrecision calculate with a fixed precision
Math::Currency for currency calculations
Bit::Vector manipulate bit vectors fast (uses C)
Math::BigIntFast Bit::Vector wrapper for big numbers
Math::Pari provides access to the Pari C library
- Math::BigInteger uses an external C library
- Math::Cephes uses external Cephes C library (no big numbers)
+ Math::Cephes uses the external Cephes C library (no
+ big numbers)
Math::Cephes::Fraction fractions via the Cephes library
Math::GMP another one using an external C library
+ Math::GMPz an alternative interface to libgmp's big ints
+ Math::GMPq an interface to libgmp's fraction numbers
+ Math::GMPf an interface to libgmp's floating point numbers
Choose wisely.