62

I just installed Perl 5.18, and I get a lot of warnings like this,

given is experimental at .\[...].pl line [...].
when is experimental at .\[...].pl line [...].
Smartmatch is experimental at C:/strawberry/perl/site/lib/[...] line [...].

Looking into these warnings -- which I've never heard mentioned anywhere -- I was only able to find this in two places,

The Perl Delta still does the most to give mention as to what's happening with those features. It's halfway down buried in the pod,

Smart match, added in v5.10.0 and significantly revised in v5.10.1, has been a regular point of complaint. Although there are a number of ways in which it is useful, it has also proven problematic and confusing for both users and implementors of Perl. There have been a number of proposals on how to best address the problem. It is clear that smartmatch is almost certainly either going to change or go away in the future. Relying on its current behavior is not recommended. Warnings will now be issued when the parser sees ~~, given, or when.

I'm confused at how the most significant change in Perl in the past 10 years could be pulled. I've started using given, when, and smartmatch all over the place. Is there any more information about these futures? How is anyone finding them "confusing?" How are these features likely to change? Is there a plan to implement these features with a module?

7

3 Answers 3

38

There are problems with the design of smart-matching. The decision of what any given TYPE ~~ TYPE should do is most often unobvious, inconsistent and/or disputed. The idea isn't to remove smart matching; it's to fix it.

[Update: In the release notes for 5.38, it was announced that smart matching will be completely removed from Perl 5.42. The following prediction is no longer accurate.]

Specifically, ~~ will be greatly simplified, as you can see in a proposal by the 5.18 pumpking. Decisions as to how two things should match will be done with helpers such as those that already exist in Smart::Match.

... ~~ any(...)

It is much more readable, much more flexible (fully extensible), and solves a number of problems (such as "When should X be considered a number, and when should it be considered a string?").

7
  • 6
    Wow, I hadn't seen Smart::Match! This is aweome! leont++ Commented Jun 5, 2013 at 2:42
  • (At least, that's my understanding of the state of affairs. None of that is set in stone, of course.)
    – ikegami
    Commented Jun 5, 2013 at 3:05
  • Based on recent chatter, I expect to see a change in 5.26 around May 2017 (and in dev releases before that).
    – ikegami
    Commented Sep 8, 2016 at 15:40
  • interesting, do you have a supporting reference? I'd be interested to read it. Commented Sep 18, 2016 at 2:29
  • 1
    For the future reader, I believe this is the thread ikegami is referring to: groups.google.com/forum/#!topic/perl.perl5.porters/7YqNduHm45E Commented Sep 18, 2016 at 2:38
23

Some insights might be gained by reading rjbs's proposed changes to smartmatch. He is the pumpking (Perl release manager) after all, so his comments and his view of the future is more relevant than most. There is also plenty of community comment on the matter; see here for instance. The 'experimental' status is in effect because, since things are likely to change in the future, it is responsible to inform users of that fact, even if we don't know what those changes will be.

11

Well, that's what's said in the description of the patch that downgraded this set of features to experimental:

The behavior of given/when/~~ are likely to change in perl 5.20.0: either smart match will be removed or stripped down. In light of this, users of these features should be warned. A category "experimental::smartmatch" warning should be issued for these features when they are used.

So while you can indeed turn these warnings off, with something like this (source):

no if $] >= 5.018, warnings => "experimental::smartmatch";

... it's just turning your eyes off the problem.

5
  • 8
    It's not about how to turn these warnings off, it's about what's wrong with Smartmatch/given/when and how will they be remedying the problem. The roadmap is just "change ahead" with no certainty of direction. Commented Jun 4, 2013 at 20:48
  • Well, I've answered the part of the question I could. For why it's confusing part, I can only refer you to this (hugely undervoted) answer - in my opinion, it describes the core point of the problem pretty darn well. ) But then again, SO is not about opinions, I suppose.
    – raina77ow
    Commented Jun 4, 2013 at 21:05
  • @EvanCarroll yes, that's what "experimental" means. It means "we don't know how this is going to work in the future, but there's a good chance it won't work like this and your code may break".
    – hobbs
    Commented Jun 5, 2013 at 4:15
  • 4
    BTW One can use use exporimental 'smartmatch'; pragma to turn the warnings off (instead of "official" and ugly way). Commented Jun 5, 2013 at 8:32
  • On the bright side, the "official" and ugly way will actually work on interpreters v5.10 through v5.18 . I imagine folks will be required to support v5.18 for more than the next week.
    – tjd
    Commented May 27, 2014 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.