match::simple(3pm) User Contributed Perl Documentation match::simple(3pm)

match::simple - simplified clone of smartmatch operator

   use v5.10;
   use match::simple;
   
   if ($this |M| $that)
   {
      say "$this matches $that";
   }

match::simple provides a simple match operator "|M|" that acts like a sane subset of the (as of Perl 5.18) deprecated smart match operator. Unlike smart match, the behaviour of the match is determined entirely by the operand on the right hand side.

If you don't like the crazy Sub::Infix operator, you can alternatively export a more normal function:

   use v5.10;
   use match::simple qw(match);
   
   if (match($this, $that))
   {
      say "$this matches $that";
   }

If you're making heavy use of this module, then this is probably your best option, as it runs significantly faster.

XS Backend

If you install match::simple::XS, a faster XS-based implementation will be used instead of the pure Perl functions. Depending on what sort of match you are doing, this is likely to be several times faster. In extreme cases, such as matching a string in an arrayref, it can be twenty-five times faster, or more. However, where $that is a single regexp, it's around 30% slower. Overall though, I think the performance improvement is worthwhile.

If you want to take advantage of this speed up, use the "match" function rather than the "|M|" operator. Otherwise all your gains will be lost to the slow implementation of operator overloading.

The constant "match::simple::IMPLEMENTATION" tells you which backend is currently in use.

Setting the "MATCH_SIMPLE_IMPLEMENTATION" environment variable to "PP" encourages match::simple to use the pure Perl backend.

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=match-simple>.

match::smart.

This module uses Exporter::Tiny.

Toby Inkster <tobyink@cpan.org>.

This software is copyright (c) 2013-2014, 2017 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

2022-06-16 perl v5.34.0