Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Best option for "switch/case" functionality?

by cheselton (Novice)
on Jun 27, 2016 at 22:48 UTC ( [id://1166705]=note: print w/replies, xml ) Need Help??


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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166705]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found