
(Neither equality operator compares the contents of eq (3,4) is false. Some other odd behavior not included in the table or the list in "Further = eq and = are true. It depends how useful this information would be. A list expression, an array initialised from that list expression and a hash initialised from the same list expression can display radically different behaviour.Įxpressions I am considering adding include ('perl'), ('perl' => 'equality'),, , 1/8 and '1/8' (note that %hash1 eq '1/8', at least on my machine).Unlike PHP and JavaScript, Perl expressions fall into equivalence classes the operators = and eq are transitive.Now we have two strings which can be compared in the usual fashion.undef becomes the empty string '', with one warning.A scalar containing the false boolean, such as $false, becomes the empty string ''.References (not shown here) become a string representing the referent's type and location in memory.Positive infinity becomes '1.#INF', negative infinity becomes '-1.#INF', NaN becomes '-1.#IND'. If a string is required, as for both sides of eq, Perl follows these rules: Now we have two numbers which can be compared in the usual fashion.A scalar containing the false boolean, such as $false, becomes 0.References (not shown here) are coerced into an integer representing the location in memory where the referent is stored.'perl' and '' become 0, with one warning. If number is required, as for both sides of =, Perl follows these rules: For a hash expression such as %hash0 or %hash1, a string such as '1/8' indicating the number of filled buckets in the hash is used.For an array expression such as or the length of the array is used.(), "the last expression in the list" is considered to be undef. For a list expression such as (0), ('0'), (1) or ('1'), the last expression in the list is used.When Perl needs to interpret an expression as a scalar, such as for binary comparisons, arithmetic or string operations, it follows these rules: Numerical equality equality catch warnings in Perl Similarly ('perl') behaves differently from and ('perl' => 'equality')īehaves differently from %hash1. Note that the literal expression () behaves differently in equality comparisons from either or %hash0. Perl lacks the = "strict equality" operator. When a comparison succeeds, 1 is returned. Note: unlike PHP and JavaScript, Perl does not have a true boolean, only false. An asterisk "*" indicates that a comparison raises a warning.

Perl has distinct operators = and eq for numerical and lexical comparisons respectively.
