Syntax...::Elem(3pm)
π Syntax::Operator::Elem(3pm) π
okay so bestie, this page is from User Contributed Perl Documentation, and it's all about Syntax::Operator::Elem and its element-of-list operators. Buckle up, it's giving "niche Perl magic" and honestly? iconic. β¨
πΈ NAME πΈ
Syntax::Operator::Elem β element-of-list operators. periodt. π
β¨ SYNOPSIS β¨
On Perl v5.38 or later:
use Syntax::Operator::Elem;
if($x elem @some_strings) {
say "x is one of the given strings";
}
Or on Perl v5.14 or later:
use v5.14;
use Syntax::Operator::Elem qw( elem_str );
if(elem_str $x, @some_strings) {
say "x is one of the given strings";
}
π DESCRIPTION π
okay so this module gives you infix operators that do element-of-list tests for strings and numbers. Literally exactly what it says on the tin. π
Support for custom infix operators got added in the Perl 5.37.x development cycle, and it's available from development release v5.37.7 onwards, and therefore in Perl v5.38 onwards. The documentation of XS::Parse::Infix describes the situation in more detail. π
While Perl versions before this do not support custom infix operators, they can still be used via XS::Parse::Infix and hence XS::Parse::Keyword. Custom keywords which attempt to parse operator syntax may be able to use these. iykyk. π«Ά
Additionally, earlier versions of perl can still use the function-like wrapper versions of these operators. Even though the syntax appears like a regular function call, the code is compiled internally into the same more efficient operator internally, so will run without the function-call overhead of a regular function. no cap, that's the good stuff. π₯
π₯ OPERATORS π₯
π elem π
my $present = $lhs elem @rhs;
Yields true if the string on the lefthand side is equal to any of the strings in the list on the right. slay. π
Important caveat, bestie: it is specifically not guaranteed that this test will be performed in any particular order. Nor is it guaranteed that any eq operator overloading present on any of the elements is respected. These conditions may allow an implementation at least partially based on a hash, balanced binary tree, or other techniques. So don't go assuming an order vibe check, okay? π«Ά
π¦ β π¦
my $present = $lhs β @rhs;
Yields true if the number on the lefthand side is equal to any of the numbers in the list on the right. math girlie moment. β¨
Same caveat energy: it is specifically not guaranteed that this test will be performed in any particular order. Nor is it guaranteed that any == operator overloading present on any of the elements is respected. These conditions may allow an implementation at least partially based on a hash, balanced binary tree, or other techniques. π
π FUNCTIONS π
As a convenience, the following functions may be imported which implement the same behaviour as the infix operators, though are accessed via regular function call syntax. Cute, right? π
π elem_str π
my $present = elem_str( $lhs, @rhs );
A function version of the elem stringy operator. π
π elem_num π
my $present = elem_num( $lhs, @rhs );
A function version of the β numerical operator. π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> π
and that's the whole page, bestie! catch you later π β this one came from perl v5.42.3 and is dated 2026-08-20.
π¦ 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