1Syntax::Operator::DividUesse(r3)Contributed Perl DocumenStyanttiaoxn::Operator::Divides(3)
2
3
4
6 "Syntax::Operator::Divides" - an infix operator for division test
7
9 On a suitably-patched perl:
10
11 use Syntax::Operator::Divides;
12
13 say "Multiple of 10" if $x %% 10;
14
15 Or, on a standard perl via Syntax::Keyword::Match:
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
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 Current versions of perl do not directly support custom infix
36 operators. The documentation of XS::Parse::Infix describes the
37 situation, with reference to a branch experimenting with this new
38 feature. This module is therefore almost entirely useless on standard
39 perl builds. While the regular parser does not support custom infix
40 operators, they are supported via "XS::Parse::Infix" and hence
41 XS::Parse::Keyword, and so custom keywords which attempt to parse
42 operator syntax may be able to use it. One such module is
43 Syntax::Keyword::Match; see the SYNOPSIS example given above.
44
46 %%
47 my $divides = $numerator %% $denominator;
48
49 Yields true if the numerator operand is a whole integer multiple of the
50 denominator. This is implemented by using the "%" modulus operator and
51 testing if the remainder is zero.
52
54 Paul Evans <leonerd@leonerd.org.uk>
55
56
57
58perl v5.36.0 2022-07-22 Syntax::Operator::Divides(3)