1Syntax::Operator::Equ(3Upsme)r Contributed Perl DocumentaStyinotnax::Operator::Equ(3pm)
2
3
4

NAME

6       "Syntax::Operator::Equ" - equality operators that distinguish "undef"
7

SYNOPSIS

9       On Perl v5.38 or later:
10
11          use v5.38;
12          use Syntax::Operator::Equ;
13
14          if($x equ $y) {
15             say "x and y are both undef, or both defined and equal strings";
16          }
17
18          if($i === $j) {
19             say "i and j are both undef, or both defined and equal numbers";
20          }
21
22       Or via Syntax::Keyword::Match on Perl v5.14 or later:
23
24          use v5.14;
25          use Syntax::Keyword::Match;
26          use Syntax::Operator::Equ;
27
28          match($str : equ) {
29             case(undef) { say "The variable is not defined" }
30             case("")    { say "The variable is defined but is empty" }
31             default     { say "The string is non-empty" }
32          }
33

DESCRIPTION

35       This module provides infix operators that implement equality tests of
36       strings or numbers similar to perl's "eq" and "==" operators, except
37       that they consider "undef" to be a distinct value, separate from the
38       empty string or the number zero.
39
40       These operators do not warn when either or both operands are "undef".
41       They yield true if both operands are "undef", false if exactly one
42       operand is, or otherwise behave the same as the regular string or
43       number equality tests if both operands are defined.
44
45       Support for custom infix operators was added in the Perl 5.37.x
46       development cycle and is available from development release v5.37.7
47       onwards, and therefore in Perl v5.38 onwards. The documentation of
48       XS::Parse::Infix describes the situation in more detail.
49
50       While Perl versions before this do not support custom infix operators,
51       they can still be used via "XS::Parse::Infix" and hence
52       XS::Parse::Keyword.  Custom keywords which attempt to parse operator
53       syntax may be able to use these. One such module is
54       Syntax::Keyword::Match; see the SYNOPSIS example given above.
55

OPERATORS

57   equ
58          my $equal = $lhs equ $rhs;
59
60       Yields true if both operands are "undef", or if both are defined and
61       contain equal string values. Yields false if given exactly one "undef",
62       or two unequal strings.
63
64   ===
65          my $equal = $lhs === $rhs;
66
67       Yields true if both operands are "undef", or if both are defined and
68       contain equal numerical values. Yields false if given exactly one
69       "undef", or two unequal numbers.
70
71       Note that while this operator will not cause warnings about
72       uninitialized values, it can still warn if given defined stringy values
73       that are not valid as numbers.
74

FUNCTIONS

76       As a convenience, the following functions may be imported which
77       implement the same behaviour as the infix operators, though are
78       accessed via regular function call syntax.
79
80       These wrapper functions are implemented using XS::Parse::Infix, and
81       thus have an optimising call-checker attached to them. In most cases,
82       code which calls them should not in fact have the full runtime overhead
83       of a function call because the underlying test operator will get
84       inlined into the calling code at compiletime. In effect, code calling
85       these functions should run with the same performance as code using the
86       infix operators directly.
87
88   is_strequ
89          my $equal = is_strequ( $lhs, $rhs );
90
91       A function version of the "equ" stringy operator.
92
93   is_numequ
94          my $equal = is_numequ( $lhs, $rgh );
95
96       A function version of the "===" numerical operator.
97

SEE ALSO

99       •   Syntax::Operator::Eqr - string equality and regexp match operator
100

AUTHOR

102       Paul Evans <leonerd@leonerd.org.uk>
103
104
105
106perl v5.38.0                      2023-07-21        Syntax::Operator::Equ(3pm)
Impressum