Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I look forward to the power of the P6 Given/When construct immensely, but I still hanker for the the limited but oh-so-useful and efficient switch/case construct. There are so many occasions when this simple integer-based dispatch mechanism is exactly all that is needed, that I think it would be worth having, in addition to the much more powerful, but equally, much less efficient Given/When construct.

I'm aware of theDamian's switch module, but it attempts to be much more than a simple switch construct, coming much closer to the given/when flexibility. The downside of that it that it is much less efficient for the predominant 'simple case'. I've also had problems with it getting confused.

Hash based dispatch tables are okay and pretty efficient, but the need to put the selected code into either a sub or runtime eval makes it less useful for things where the selected code is minimal and speed important. Calling a sub to increment or decrement a count is high overhead if your scanning long strings and maintaining counts as you go.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Re: Re: Re: Re: Perl Idioms Explained: && and || "Short Circuit" operators by BrowserUk
in thread Perl Idioms Explained - && and || "Short Circuit" operators by davido

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found