match::simple(3)
okay bestie, welcome to match::simple(3) β yes, the User Contributed Perl Documentation page β and it's giving "smartmatch but make it sane" π
β¨
πΈ NAME πΈ
match::simple β a simplified clone of the smartmatch operator. That's the whole name, no cap π«Ά
β¨ SYNOPSIS β¨
use v5.10;
use match::simple;
if ( $this |M| $that ) {
say "$this matches $that";
}
π¦ DESCRIPTION π¦
okay so match::simple gives you a simple match operator, |M|, and it acts like a sane subset of the smart match operator that's been deprecated as of Perl 5.18 π. Unlike smart match, the behaviour of the match is determined entirely by the operand on the right hand side. Right-hand side is the main character here, periodt π
- If the right hand side is
undef, then there is only a match if the left hand side is alsoundef. That's it. Both gotta beundefor it's a no π - If the right hand side is a non-reference, then the match is a simple string match. Easy peasy π
- If the right hand side is a reference to a regexp, then the left hand is evaluated. Yep, that's what it says, bestie π
- If the right hand side is a code reference, then it is called in a boolean context with the left hand side being passed as an argument. Code ref said "I'll decide" β¨
- If the right hand side is an object which provides a
MATCHmethod, then this is called as a method, with the left hand side being passed as an argument. Object with main character energy π - If the right hand side is an object which overloads
~~, then this will be used. Respect the overload π - If the right hand side is an arrayref, then the operator recurses into the array, with the match succeeding if the left hand side matches any array element. It's giving "check every single one" π₯
- If any other value appears on the right hand side, the operator will croak. So don't try it unless you want the croak π
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. Slay for efficiency π
π 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. Highkey a trade-off, but a cute one π
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. Don't let the vibe check steal your speed π
The constant match::simple::IMPLEMENTATION tells you which backend is currently in use. It's literally the label on the backend π
π± Environment π±
Setting the MATCH_SIMPLE_IMPLEMENTATION environment variable to PP encourages match::simple to use the pure Perl backend. Pure Perl said "let me cook" π
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-match-simple/issues>. Do it for the plot π
π SEE ALSO π
match::smartmatch::simple::sugar
This module uses Exporter::Tiny. Tiny but iconic π§
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. Respect the author, bestie π«Ά
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2013-2014, 2017, 2022-2023 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.
π DISCLAIMER OF WARRANTIES π
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.
fr fr read that one, it's important π
okay that's the whole page! source/version: perl v5.40.0, date: 2024-07-19, and it's match::simple(3) signing off β bye bestie, go match something cute ππ«Άβ¨
π¦ where this page comes from
- epel 10: perl-match-simple 0.012-5.el10_0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms