Syntax...or::In(3pm)
π NAME π
Syntax::Operator::In β an infix element-of-list meta-operator, and yes bestie the page title up top literally gets chopped to Syntax...or::In(3pm) because man page headers are dramatic like that π the full name is the slay one above π
β¨ SYNOPSIS β¨
On Perl v5.38 or later:
use Syntax::Operator::In;
if($x in:eq @some_strings) {
say "x is one of the given strings";
}
π¦ DESCRIPTION π¦
Okay so this module hands you an infix meta-operator that does an element-of-list test β on strings or numbers, your pick πΈ
Support for custom infix operators got added back in the Perl 5.37.x development cycle, and it's available from development release v5.37.7 onwards, which means it's in Perl v5.38 onwards, periodt π The docs for XS::Parse::Infix describe the whole situation in more detail if you want the lore.
Now, Perl versions before that don't support custom infix operators at all β but ngl you can still use them via XS::Parse::Infix and hence XS::Parse::Keyword π«Ά Custom keywords that attempt to parse operator syntax may be able to use these too.
If you're after operators that already specialize on string or numerical equality, go look at Syntax::Operator::Elem instead, iykyk π
π₯ OPERATORS π₯
π in
my $present = $lhs in:OP @rhs;
my $present = $lhs in<OP> @rhs;
Yields true if the value on the lefthand side is equal to any of the values in the list on the right β according to some equality test operator OP β¨
That test operator has to be either eq for string match, or == for number match, or literally any other custom infix operator that's registered in the XPI_CLS_EQUALITY classification π
There are currently two accepted forms of the syntax for this operator: one uses a prefix colon, the other a circumfix pair of angle-brackets. They are entirely identical in semantics β the only difference is the surface-level syntax used to notate them π That's because the author is still entirely undecided on which notation is better in terms of readable neatness, flexibility, parsing ambiguity and so on. It's somewhat of an experiment to see which one will eventually win π
π TODO π
- Improve runtime performance of compiletime-constant sets of strings, by detecting when the RHS contains string constants and convert it into a hash lookup π
- Consider cross-module integration with
Syntax::Keyword::Match, permitting
match($val : elem) {
case(@arr_of_strings) { ... }
}
Or perhaps this would be too weird, and maybe match/case should have an "any-of" list/array matching ability itself. See also <https://rt.cpan.org/Ticket/Display.html?id=143482> π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> β icon, legend, the moment π
okay that's the whole page, you're all caught up bestie π«Ά this was perl v5.42.3, dated 2026-08-20, living in the User Contributed Perl Documentation section as Syntax...or::In(3pm) β go be the main character of your own element-of-list test βπ
π¦ where this page comes from
- ubuntu stonking: libsyntax-operator-in-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