Syntax...or::Eqr(3pm)
π NAME
Syntax::Operator::Eqr β a string equality and regexp match operator, all in one lil cutie π
β¨ SYNOPSIS
okay so first up, on Perl v5.38 or later you can literally just do this:
use v5.38;
use Syntax::Operator::Eqr;
if($str eqr $pat) {
say "x and y are both undef, or both defined and equal strings, " .
"or y is a regexp that matches x";
}
orrrr, if you're on Perl v5.14 or later, you can vibe with it through Syntax::Keyword::Match instead π¦
use v5.14;
use Syntax::Keyword::Match;
use Syntax::Operator::Eqr;
match($str : eqr) {
case(undef) { say "The variable is not defined" }
case("") { say "The variable is defined but is empty" }
case(qr/^.$/) { say "The variable contains exactly one character" }
default { say "The string contains more than one" }
}
π DESCRIPTION
So this module gives you an infix operator that does a matching thing, and the way it behaves depends entirely on what the right-hand side is π. Three moods:
- if the right-hand side is
undef, it's true only when the left-hand side is alsoundef; - if the right-hand side is a quoted regexp object, it acts just like Perl's
=~pattern-matching operator; - if it's neither of those, it acts like the
eqoperator. periodt.
And the iconic part? This operator does not warn when either operand (or both!) is undef π no nagging, no drama.
Now, the lore: support for custom infix operators got added during the Perl 5.37.x development cycle, available from development release v5.37.7 onwards β which means it's in Perl v5.38 onwards β¨. The docs for XS::Parse::Infix describe the whole situation in more detail if you're curious.
And even though Perl versions before that don't support custom infix operators, you can still use them via XS::Parse::Infix and therefore XS::Parse::Keyword π«Ά. Custom keywords that try to parse operator syntax may be able to use these. One such module is Syntax::Keyword::Match; peep the SYNOPSIS example above, it's giving main character energy π
πΈ Comparison With Smartmatch
At first glance this looks a lil similar to core perl's ill-fated smartmatch operator (~~), but bestie, this version is so much simpler π.
It does not try to figure out whether a stringy or numerical match is preferred, and it does not attempt to make sense of any ARRAY, HASH, CODE or other complicated container values on either side. Nope. Its behaviour is, in effect, entirely determined by the value on its righthand side β the three cases of undef, some qr/.../ object, or anything else. Simple as that π
And that's exactly what makes it behave sensibly with the match/case syntax provided by Syntax::Keyword::Match β¨
π₯ OPERATORS
β eqr
my $matches = $lhs eqr $rhs;
Yields true if both operands are undef, or if the right-hand side is a quoted regexp value that matches the left-hand side, or if both are defined and contain equal string values π. Yields false if you give it exactly one undef, two unequal strings, or a string that doesn't match the pattern. No cap.
π FUNCTIONS
As a convenience, you can import the following functions β they implement the exact same behaviour as the infix operators, they're just accessed via regular function call syntax π«Ά.
These wrapper functions are implemented using XS::Parse::Infix, so they've got an optimising call-checker attached to them β¨. In most cases, code that calls them shouldn't actually have the full runtime overhead of a function call, because the underlying test operator gets inlined into the calling code at compiletime. So effectively, code calling these functions should run with the same performance as code using the infix operators directly π₯ iconic behaviour tbh.
π is_eqr
my $matches = is_eqr( $lhs, $rhs );
A function version of the eqr stringy operator π
π¦ SEE ALSO
Syntax::Operator::Equβ equality operators that distinguishundef
π AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
okay that's the whole page, bestie β mwah π this lil beauty is from perl v5.42.3, dated 2026-08-20, and it's part of the User Contributed Perl Documentation π go forth and match responsibly πΈ
π¦ 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