The advantage to case statements is that each element is not mutually exclusive, as you have with a single if/elsif/else structure
So, in pseudocode, you might do something like:
switch (value) {
case 'needs_slight_cleaning':
&clean_up_values;
case 'good value':
&do_whatever_you_need_to;
break;
case 'totally unrelated';
&do_something_else;
break;
default:
&do_some_default_thing;
}
Note how there is no 'break' between the first two cases, so something that matches the first case will run '&clean_up_values' and '&do_whatever_you_need_to';
It's not an absolutely necessary control structure, but there are some times when it sure does come in handy. (most times when you have a giant if/elseif/else tree, where you're repeating large blocks of it).
Update: I forgot to answer the questions as they were asked:
- What type of new control structures you would like to have in Perl?
- I'm fine with the current structures
- What would be your consideration for the design of control structures ?
- Anything that helps me get my work done
- Would that make your task easier?
- switch/case statements, for the reason stated above.
Can you mimic them with current version (5.6+)?- Yes. With goto.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.