1Syntax::Operator::In(3)User Contributed Perl DocumentatioSnyntax::Operator::In(3)
2
3
4

NAME

6       "Syntax::Operator::In" - infix element-of-list meta-operator
7

SYNOPSIS

9       On Perl v5.38 or later:
10
11          use Syntax::Operator::In;
12
13          if($x in:eq @some_strings) {
14             say "x is one of the given strings";
15          }
16

DESCRIPTION

18       This module provides an infix meta-operator that implements a element-
19       of-list test on either strings or numbers.
20
21       Support for custom infix operators was added in the Perl 5.37.x
22       development cycle and is available from development release v5.37.7
23       onwards, and therefore in Perl v5.38 onwards. The documentation of
24       XS::Parse::Infix describes the situation in more detail.
25
26       While Perl versions before this do not support custom infix operators,
27       they can still be used via "XS::Parse::Infix" and hence
28       XS::Parse::Keyword.  Custom keywords which attempt to parse operator
29       syntax may be able to use these.
30
31       For operators that already specialize on string or numerical equality,
32       see instead Syntax::Operator::Elem.
33

OPERATORS

35   in
36          my $present = $lhs in:OP @rhs;
37
38          my $present = $lhs in<OP> @rhs;
39
40       Yields true if the value on the lefhand side is equal to any of the
41       values in the list on the right, according to some equality test
42       operator "OP".
43
44       This test operator must be either "eq" for string match, or "==" for
45       number match, or any other custom infix operator that is registered in
46       the "XPI_CLS_EQUALITY" classification.
47
48       There are currently two accepted forms of the syntax for this operator,
49       using either a prefix colon or a circumfix pair of angle-brackets. They
50       are entirely identical in semantics, differing only in the surface-
51       level syntax to notate them. This is because I'm still entirely
52       undecided on which notation is better in terms of readable neatness,
53       flexibility, parsing ambiguity and so on. This is somewhat of an
54       experiment to see which will eventually win.
55

TODO

57       •   Improve runtime performance of compiletime-constant sets of
58           strings, by detecting when the RHS contains string constants and
59           convert it into a hash lookup.
60
61       •   Consider cross-module integration with Syntax::Keyword::Match,
62           permitting
63
64              match($val : elem) {
65                 case(@arr_of_strings) { ... }
66              }
67
68           Or perhaps this would be too weird, and maybe "match/case" should
69           have an "any-of" list/array matching ability itself. See also
70           <https://rt.cpan.org/Ticket/Display.html?id=143482>.
71

AUTHOR

73       Paul Evans <leonerd@leonerd.org.uk>
74
75
76
77perl v5.36.1                      2023-07-26           Syntax::Operator::In(3)
Impressum