match::smart(3)
π NAME π
match::smart β clone of smartmatch operator. Hiiii bestie! Welcome to the match::smart(3) page, aka this User Contributed Perl Documentation moment. If you miss the old smartmatch vibe, this module is literally your comfort blanket π«Ά.
β¨ SYNOPSIS β¨
Okay so first, the iconic |M| operator era:
use v5.10;
use match::smart;
if ($this |M| $that)
{
say "$this matches $that";
}
No cap, that's the whole flex. If you don't like the crazy Sub::Infix operator, you can alternatively export a more normal function:
use v5.10;
use match::smart qw(match);
if (match($this, $that))
{
say "$this matches $that";
}
πΈ DESCRIPTION πΈ
match::smart provides a match operator |M| that acts like more or less identically to the (as of Perl 5.18) deprecated smart match operator. Lowkey iconic behaviour, highkey useful.
If you don't like the crazy Sub::Infix operator, you can alternatively export a more normal function:
use v5.10;
use match::smart qw(match);
if (match($this, $that))
{
say "$this matches $that";
}
π¦ Differences with ~~ π¦
There were major changes to smart match between 5.10.0 and 5.10.1. This module attempts to emulate the behaviour of the operator in more recent versions of Perl. In particular, 5.18.0 (minus the warnings). Divergences not noted below should be considered bugs. Fr fr, don't ignore that part π.
While the real smart match operator implicitly takes references to operands that are hashes or arrays, match::smart's operator does not. So this:
@foo ~~ %bar # means: \@foo ~~ \%bar
@foo |M| %bar # means: scalar(@foo) |M| scalar(%bar)
If you want the \@foo ~~ \%bar behaviour, you need to add the backslashes yourself:
\@foo |M| \%bar
Similarly:
"foo" ~~ /foo/ # works
"foo" |M| /foo/ # no worky!
"foo" |M| qr/foo/ # do this instead
match::smart treats the "MATCH" method on blessed objects (if it exists) like an overloaded "~~". This is for compatibility with match::simple, and for compatibility with versions of Perl that don't have documented support for overloading "~~". Very compatibility, much thoughtful, slay π
.
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-match-simple/issues>. Bestie, don't suffer in silence with a weird edge case β send it to the issue tracker π«Ά.
π SEE ALSO π
match::simple.
This module uses Exporter::Tiny.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>.
π 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.
Okay bestie, that's the whole match::smart(3) page β mwah! π This one came from perl v5.40.0 and is dated 2024-07-19, so you know exactly what era of manual-page excellence you're in πβ¨
π¦ 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