Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

I see now that I basiclly took it from the wrong concept... (what I initially though about had more to do with something like eval then with switch)

I have no idea wheter or not it would be a good idea to implement what I was thinking about... I'll continue explaining and then you can make up your mind... I was thinking about creating a 'handler' that is run at the end if one (or more) case-statements matched...

I'm afraid I didn't explain to well and that it might be easier to explain it with an example/code, so that's what I will do now:

Assume that at the end of each case there is some default action that should be taken (update a hash with a list of matches or something). With the current implementation there are two ways to accomplish this:

a) adding the code it in each code-ref (by calling another subroutine)
b) using something like $case->("something") and some_other_code; (although in this case it would depend on the return value, but let's assume it returns a true value when the code-ref was run)

Both of these have some disadvantages, the first one has the disadvantage of the duplicate function-call and the second depends on the return value

What my suggestion was about was to be able to set up something like 'FINAL' (or 'CONTINUE') => sub { ... } which will run the code (add it to a hash or whatever) if a case returned true


In reply to Re^3: Switch/case as a jump table with C-style fall-through by Animator
in thread Switch/case as a dispatch table with C-style fall-through by Roy Johnson

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 lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found