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