1Syntax::Operator::Elem(U3spemr)Contributed Perl DocumentSaytnitoanx::Operator::Elem(3pm)
2
3
4

NAME

6       "Syntax::Operator::Elem" - element-of-list operators
7

SYNOPSIS

9       On Perl v5.38 or later:
10
11          use Syntax::Operator::Elem;
12
13          if($x elem @some_strings) {
14             say "x is one of the given strings";
15          }
16
17       Or on Perl v5.14 or later:
18
19          use v5.14;
20          use Syntax::Operator::Elem qw( elem_str );
21
22          if(elem_str $x, @some_strings) {
23             say "x is one of the given strings";
24          }
25

DESCRIPTION

27       This module provides infix operators that implement element-of-list
28       tests for strings and numbers.
29
30       Support for custom infix operators was added in the Perl 5.37.x
31       development cycle and is available from development release v5.37.7
32       onwards, and therefore in Perl v5.38 onwards. The documentation of
33       XS::Parse::Infix describes the situation in more detail.
34
35       While Perl versions before this do not support custom infix operators,
36       they can still be used via "XS::Parse::Infix" and hence
37       XS::Parse::Keyword.  Custom keywords which attempt to parse operator
38       syntax may be able to use these.
39
40       Additionally, earlier versions of perl can still use the function-like
41       wrapper versions of these operators. Even though the syntax appears
42       like a regular function call, the code is compiled internally into the
43       same more efficient operator internally, so will run without the
44       function-call overhead of a regular function.
45

OPERATORS

47   elem
48          my $present = $lhs elem @rhs;
49
50       Yields true if the string on the lefthand side is equal to any of the
51       strings in the list on the right.
52
53       Note that it is specifically not guaranteed that this test will be
54       performed in any particular order. Nor is it guaranteed that any "eq"
55       operator overloading present on any of the elements is respected. These
56       conditions may allow an implementation at least partially based on a
57       hash, balanced binary tree, or other techniques.
58
59   
60          my $present = $lhs ∈ @rhs;
61
62       Yields true if the number on the lefthand side is equal to any of the
63       numbers in the list on the right.
64
65       Note that it is specifically not guaranteed that this test will be
66       performed in any particular order. Nor is it guaranteed that any "=="
67       operator overloading present on any of the elements is respected. These
68       conditions may allow an implementation at least partially based on a
69       hash, balanced binary tree, or other techniques.
70

FUNCTIONS

72       As a convenience, the following functions may be imported which
73       implement the same behaviour as the infix operators, though are
74       accessed via regular function call syntax.
75
76   elem_str
77          my $present = elem_str( $lhs, @rhs );
78
79       A function version of the "elem" stringy operator.
80
81   elem_num
82          my $present = elem_num( $lhs, @rhs );
83
84       A function version of the "∈" numerical operator.
85

AUTHOR

87       Paul Evans <leonerd@leonerd.org.uk>
88
89
90
91perl v5.38.0                      2023-07-26       Syntax::Operator::Elem(3pm)
Impressum