1Syntax::Operator::DividUesse(r3pCmo)ntributed Perl DocumSeynnttaatxi:o:nOperator::Divides(3pm)
2
3
4

NAME

6       "Syntax::Operator::Divides" - an infix operator for division test
7

SYNOPSIS

9       On Perl v5.38 or later:
10
11          use Syntax::Operator::Divides;
12
13          say "Multiple of 10" if $x %% 10;
14
15       Or via Syntax::Keyword::Match on Perl v5.14 or later:
16
17          use v5.14;
18          use Syntax::Keyword::Match;
19          use Syntax::Operator::Divides;
20
21          foreach ( 1 .. 100 ) {
22             match( $_ : %% ) {
23                case(15) { say "FizzBuzz" }
24                case(3)  { say "Fizz" }
25                case(5)  { say "Buzz" }
26                default  { say $_ }
27             }
28          }
29

DESCRIPTION

31       This module provides an infix operator that implements an integer
32       divides test which returns true if the lefthand operand is a whole
33       multiple of the righthand.
34
35       Support for custom infix operators was added in the Perl 5.37.x
36       development cycle and is available from development release v5.37.7
37       onwards, and therefore in Perl v5.38 onwards. The documentation of
38       XS::Parse::Infix describes the situation in more detail.
39
40       While Perl versions before this do not support custom infix operators,
41       they can still be used via "XS::Parse::Infix" and hence
42       XS::Parse::Keyword.  Custom keywords which attempt to parse operator
43       syntax may be able to use these. One such module is
44       Syntax::Keyword::Match; see the SYNOPSIS example given above.
45

OPERATORS

47   %%
48          my $divides = $numerator %% $denominator;
49
50       Yields true if the numerator operand is a whole integer multiple of the
51       denominator. This is implemented by using the "%" modulus operator and
52       testing if the remainder is zero.
53

FUNCTIONS

55       As a convenience, the following functions may be imported which
56       implement the same behaviour as the infix operators, though are
57       accessed via regular function call syntax.
58
59       These wrapper functions are implemented using XS::Parse::Infix, and
60       thus have an optimising call-checker attached to them. In most cases,
61       code which calls them should not in fact have the full runtime overhead
62       of a function call because the underlying test operator will get
63       inlined into the calling code at compiletime. In effect, code calling
64       these functions should run with the same performance as code using the
65       infix operators directly.
66
67   is_divisor
68          my $divides = is_divisor( $numerator, $denominator );
69
70       A function version of the "%%" operator.
71

AUTHOR

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