Take the 2-minute tour ×

I've seen a number of comments across the web Perl's smart-match operator is broken. I know it originally was part of Perl 6, then was implemented in Perl 5.10 off of an old version of the spec, and was then corrected in 5.10.1 to match the current Perl 6 spec.

Is the problem fixed in 5.10.1+, or are there other problems with the smart-match operator that make it troublesome in practice?

What are the problems?

Is there a yet-more-updated version (Perl 6, perhaps) that fixes the problems?

Edit: To clarify, I'm not asking about bugs, but rather the opinion that the intended behavior of ~~ is bad.

share|improve this question
Wouldn't this be better off on SO? –  user39685 Nov 28 '11 at 22:34
So seems to hate questions that can't be answered with code snippets these days. –  Sean McMillan Nov 28 '11 at 22:35
I don't think it belongs on SO, it asks for a conceptual explanation on why Perl's smart-match operator is considered broken. –  Yannis Rizos Nov 28 '11 at 22:41
From what I see in your link, it appears that smart-match is (or was) recursive, so it could probably lead to infinite recursion just because an array (possibly indirectly) contains a reference to itself. –  user281377 Nov 28 '11 at 23:13
@SeanMcMillan - SO hates a lot of things these days :/ –  ldigas Dec 1 '11 at 16:08

2 Answers 2

People often confuse the issues that arise with the smartmatch operator with those that arise with the given/when construct, such as the problem of lexical $_.

I’ve come to the opinion that if you use the smartmatch operator only on literals, that you will not go insane. I can make no promises about any other situation. Trying to figure out what $a ~~ $b is doing is enough to drive any decent human being to run screaming in madness, and to take up another programming language altogether.

Or at least, that’s the take I got from Larry when he was editing the smartmatch section of the 4th edition of Programming Perl.

share|improve this answer

The smart match operator wasn't "broken", but it had lots of bugs. Perl v5.12 fixed that, and Perl v5.14 perfected it IMHO. So, to answer your question, Perl v5.12 and up fixes this problem. You can try it with later versions of Perl v5.10, but I know it works better in Perl 5.12+.

Edit: To answer your edit, see this blog. After reading the article, I believe it sufficiently answered your question.

share|improve this answer

Your Answer


