5

I'm using Perl 5.24 right now and smartmatch is a great, versatile operator, for example,

%foobar ~~ @foo; 

and all the intricacies therein.

I understand from 5.27 onwards its functionality will be reduced to smartwatches involving,

$foo = qr/foo/; 

Okay so I'm going to have to rewrite my data pipelines to be compliant.

My question is, if confirmed what is the different between,

'foo' ~~ $foo;

and,

 'foo' =~ /$foo/;

It strikes me that smartmatch is being removed in all but name. Am I right, and if not what am I missing?

History

It has an unusual history, and it must be stressed its classed as experimental. I'm charting what I know. I guess many of you will know more, any input would be helpful because its an example (to students) of language evolution:

  • 5.10 first introduced
  • 5.14 introduced %foobar ~~ @foo type matches
  • 5.27 Removed in all but name only? Still experimental?
M__
  • 614
  • 2
  • 10
  • 25
  • 1
    5.10.1 made some major changes to it. (Yeah, in a maint release. They really dropped the ball when it came to smartmatch.) – ikegami Apr 24 '19 at 14:35
  • 1
    Smartmatch was going to be removed from 5.28 --a patch was even submitted-- but too many people are using this broken feature. The way forward is unclear, but smartmatching remains unchanged (and subject to change/removal at any time) for now. – ikegami Apr 24 '19 at 14:43

1 Answers1

5

Smart match is still experimental.

If we had time machines, most people working on the development of perl would go back in time, and remove smart match from perl5. The only thing smart match has done is showing clearly that taking something from perl6 and trying to bolt that into perl5 isn't going to work if it's anything more complicated than say.

Noone knows what the future of smart match in perl5 will be. There's no agreement on what it should be. If it wasn't for the dreaded "backwards compatability", smart match would have been dead and buried years ago.

Save yourself a world of pain, and don't use smart match.

  • 1
    I hope you'll excuse my ignorance, but it sounds like you're referring to yourself as part of the team developing perl. Is there any chance you can mention your role in the project in your answer here? – Conspicuous Compiler Apr 23 '19 at 22:49
  • 2
    Hrm, tried to find [a concise summary of smart match at the archives of perl5.porters](https://www.nntp.perl.org/group/perl.perl5.porters/). I'm glad you provided a summary here, as I didn't find distillation terribly easy through the web interface to the archives. – Conspicuous Compiler Apr 23 '19 at 23:13
  • I will reluctantly sign this off. Essentially, it appears my belief that smartwatch has been removed from 5.27 was just a rumour. If implemented it forces removal from current code (we have no option). Questions remain as to what was so wrong with smartmatch and whilst I heard a rumour Damian Conway never liked it (just a rumour), its not clear why there is such negativity. – M__ Apr 25 '19 at 10:32
  • 1
    @MichaelG. "_what was so wrong with smartmatch_" -- it's a lot and it goes deep, so it's hard to fix. Its design is extremely complicated (and inconsistent), what makes it difficult (actually _difficult_) to figure out what it's going to do in many cases, or how to use it correctly. You can work with it as you'd expect (a feature to be used) only for the most basic uses -- while it's packed with ten times more. Hindsight's easy as we know, but this really isn't good and shouldn't be used. – zdim May 20 '19 at 04:19
  • 1
    @MichaelG. Some resources: [this page](https://stackoverflow.com/q/16927024/4653379), comments/links under [this question](https://stackoverflow.com/q/49328308/4653379) – zdim May 20 '19 at 04:22
  • @ConspicuousCompiler "_tried to find_" -- here's [a summary of sorts](https://www.nntp.perl.org/group/perl.perl5.porters/2017/08/msg245769.html) that popped up while I was putting together above comments. Those links have more. – zdim May 20 '19 at 04:29