Syntax...or::Equ(3pm)
π Syntax::Operator::Equ(3pm) β bestie edition
okay so the actual manual name is Syntax::Operator::Equ and it's a Perl module (3pm, perl's own doc set) β and babes, it's about equality operators that actually know the difference between undef and "empty". no cap. π«Ά
β¨ NAME β¨
"Syntax::Operator::Equ" β equality operators that distinguish "undef" π
π SYNOPSIS π
So on Perl v5.38 or later you can do this whole thing:
use v5.38;
use Syntax::Operator::Equ;
if($x equ $y) {
say "x and y are both undef, or both defined and equal strings";
}
if($i === $j) {
say "i and j are both undef, or both defined and equal numbers";
}
Or, if you're chilling on Perl v5.14 or later, you can take the scenic route via Syntax::Keyword::Match:
use v5.14;
use Syntax::Keyword::Match;
use Syntax::Operator::Equ;
match($str : equ) {
case(undef) { say "The variable is not defined" }
case("") { say "The variable is defined but is empty" }
default { say "The string is non-empty" }
}
likeβ¦ look at that. three whole different flavours of "nothing here" and the match block tells them apart. iconic. π
πΈ DESCRIPTION πΈ
So this module gives you infix operators that do equality tests on strings or numbers, basically like perl's own "eq" and "==" β except here's the twist: they treat "undef" as its own whole entire distinct value, separate from the empty string or the number zero. it's giving main character energy for undef. πβ¨
These operators do not warn when either or both operands are "undef" β no nagging, no drama. The rules are literally:
- both operands
"undef"β true - exactly one operand
"undef"β false - otherwise (both defined) β they behave exactly the same as the regular string or number equality tests π¦
Support for custom infix operators landed in the Perl 5.37.x development cycle, available from development release v5.37.7 onwards, and therefore in Perl v5.38 onwards. The docs for XS::Parse::Infix spill the whole situation in more detail if you're nosy (respectfully).
And here's the cute part: even though Perl versions before that don't support custom infix operators, you can still use these via "XS::Parse::Infix" and hence XS::Parse::Keyword. Custom keywords that attempt to parse operator syntax may be able to use them β one such module is Syntax::Keyword::Match, and yes, that's the SYNOPSIS example up there. slay. π
β OPERATORS β
π equ
my $equal = $lhs equ $rhs;
Yields true if both operands are "undef", or if both are defined and contain equal string values. Yields false if given exactly one "undef", or two unequal strings. simple as that bestie π
π ===
my $equal = $lhs === $rhs;
Yields true if both operands are "undef", or if both are defined and contain equal numerical values. Yields false if given exactly one "undef", or two unequal numbers. π₯
β οΈ okay important heads up: while this operator will not cause warnings about uninitialized values, it can still warn if given defined stringy values that are not valid as numbers. so likeβ¦ don't get cocky. π
π§ FUNCTIONS π§
As a convenience (love that for us), the following functions can be imported, and they implement the same behaviour as the infix operators β but you get at them through regular function call syntax. π
These wrapper functions are implemented using XS::Parse::Infix, which means they've got an optimising call-checker attached. In most cases, code that calls them should not in fact have the full runtime overhead of a function call, because the underlying test operator gets inlined into the calling code at compiletime. so basically: code calling these functions should run with the same performance as code using the infix operators directly. highkey efficient. β‘
π is_strequ
my $equal = is_strequ( $lhs, $rhs );
A function version of the "equ" stringy operator. π¦
π
is_numequ
my $equal = is_numequ( $lhs, $rgh );
A function version of the "===" numerical operator. (and yes, the second parameter is literally spelled $rgh up there β keeping it exactly as written, iykyk π)
π SEE ALSO π
Syntax::Operator::Eqrβ string equality and regexp match operator β¨
π«Ά AUTHOR π«Ά
Paul Evans <leonerd@leonerd.org.uk> β thank you king π
and that's the whole page, bestie π this beauty shipped as perl v5.42.3, dated 2026-08-20, filed under Syntax...or::Equ(3pm) β go forth and distinguish your undefs, you absolute icon πΈπβ
π¦ where this page comes from
- ubuntu stonking: libsyntax-operator-equ-perl 0.10-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms