in reply to Best option for "switch/case" functionality?

Thanks for all of your posts and wonderful insights. I think I may have worded my request in such a way that it put focus on the wrong issue: the warnings for using the feature.

When the issue I was actually hoping to get addressed, more specifically, was that perls <5.18 didn't recognize the "experimental::smartmatch" and would throw a compile-time error. This prevented the script from even running to throw warnings or anything else.

I think haukex inadvertently came across the solution as no if $] ge '5.018', warnings => "experimental::smartmatch"; seems to work fine. What I was using (use warnings;\nno warnings "experimental::smartmatch";) threw the error. I guess the seemingly minor difference in syntax solves the issue.

Replies are listed 'Best First'.
Re^2: Best option for "switch/case" functionality? (magic numbers)
by tye (Sage) on Jun 28, 2016 at 18:18 UTC

    Rather than hard-code the "magic number"` '5.018', I'd go with

    BEGIN { eval { require warnings; warnings->unimport('experimental::sma +rtmatch') } }

    - tye        

      Isn't that lexical to the BEGIN{} block?

        Nope. Otherwise, 'use' couldn't work as it is just syntactic sugar for pretty much what I wrote (well, 'no' more than 'use' in this case). Now, if you put 'use' in a BEGIN block, then it could have impacts lexically scoped to the BEGIN block, but that is because it would be short for:

        BEGIN { BEGIN { require ...; ...->import( ... ) } }

        - tye