Hi cheselton,

The easiest way to get rid of the warning on all Perls v5.10 and above is the following, taken from here, which also briefly explains the rationale for making it experimental:

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

And I think the best way to enable the smartmatch feature is use 5.010_001; (see "Feature Bundles" and the section following it, "Implicit Loading"). I suggest Perl v5.10.1 because there were some significant changes to the way smartmatching and given/when works.

Update: I should add that because of its experimental state and the fact that the behaviour might change later, I now avoid given/when and use if/elsif or one of the other alternatives like dispatch tables instead. In fact, I sometimes begin Perl scripts with the somewhat clumsy use 5.010; no feature 'switch'; when I want to have v5.10 as my minimum version but want to avoid accidentally using given/when.

There's also been several discussions here on PerlMonks, for example Bring back the smartmatch operator (but with sane semantics this time)!, which includes this post listing some of the alternatives available on CPAN. Hopefully we will get back a working given/when someday :-)

Hope this helps,
-- Hauke D

Update: Expanded post slightly. Yet Another Update: Used ge rather than >= as explained here.


In reply to Re: Best option for "switch/case" functionality? by haukex
in thread Best option for "switch/case" functionality? by cheselton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.