Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by BrowserUk (Patriarch)
on Jun 27, 2016 at 20:28 UTC ( [id://1166693]=note: print w/replies, xml ) Need Help??


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

A hash of coderefs is perfect if your cases are all constants, but if you want something that is closer to Switch or given/when, without the headaches, take a look at Dan Brook's Switch::Perlish which allows (for example) a coderef against a hash, or a regex against an array, and many more combinations; but with clear and sane rules about what each combination does.

It's what given/when with smart matching could have been; but with slightly more cumbersome, but still eminently readable syntax.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
  • Comment on Re: Best option for "switch/case" functionality?

Replies are listed 'Best First'.
Re^2: Best option for "switch/case" functionality?
by choroba (Cardinal) on Jun 27, 2016 at 21:02 UTC
    I provided a patch for the module to work on 5.14+. Thanks for pointing me to an interesting module.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Looking at the module it doesn't seem to have been maintained since 2006. And (if memory serves) Dan Brook's PM handle was broquaint, which hasn't been logged into since 2013.

      So, whether your patch will get applied...


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
        His latest upload to CPAN happened 18 days ago, so we'll see. In the meantime, anyone can apply the patch themselves.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166693]
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-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found