1match::smart(3) User Contributed Perl Documentation match::smart(3)
2
3
4
6 match::smart - clone of smartmatch operator
7
9 use v5.10;
10 use match::smart;
11
12 if ($this |M| $that)
13 {
14 say "$this matches $that";
15 }
16
18 match::smart provides a match operator "|M|" that acts like more or
19 less identically to the (as of Perl 5.18) deprecated smart match
20 operator.
21
22 If you don't like the crazy Sub::Infix operator, you can alternatively
23 export a more normal function:
24
25 use v5.10;
26 use match::smart qw(match);
27
28 if (match($this, $that))
29 {
30 say "$this matches $that";
31 }
32
33 Differences with ~~
34 There were major changes to smart match between 5.10.0 and 5.10.1. This
35 module attempts to emulate the behaviour of the operator in more recent
36 versions of Perl. In particular, 5.18.0 (minus the warnings).
37 Divergences not noted below should be considered bugs.
38
39 While the real smart match operator implicitly takes references to
40 operands that are hashes or arrays, match::smart's operator does not.
41
42 @foo ~~ %bar # means: \@foo ~~ \%bar
43 @foo |M| %bar # means: scalar(@foo) |M| scalar(%bar)
44
45 If you want the "\@foo ~~ \%bar" behaviour, you need to add the
46 backslashes yourself:
47
48 \@foo |M| \%bar
49
50 Similarly:
51
52 "foo" ~~ /foo/ # works
53 "foo" |M| /foo/ # no worky!
54 "foo" |M| qr/foo/ # do this instead
55
56 match::smart treats the "MATCH" method on blessed objects (if it
57 exists) like an overloaded "~~". This is for compatibility with
58 match::simple, and for compatibility with pre-5.10 Perls that don't
59 allow overloading "~~".
60
62 Please report any bugs to
63 <http://rt.cpan.org/Dist/Display.html?Queue=match-simple>.
64
66 match::simple.
67
68 This module uses Exporter::Tiny.
69
71 Toby Inkster <tobyink@cpan.org>.
72
74 This software is copyright (c) 2013-2014, 2017 by Toby Inkster.
75
76 This is free software; you can redistribute it and/or modify it under
77 the same terms as the Perl 5 programming language system itself.
78
80 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
81 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
82 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
83
84
85
86perl v5.28.1 2017-01-31 match::smart(3)