No such thing as a small change | |
PerlMonks |
Re: Succinct switch statementby jakobi (Pilgrim) |
on Oct 23, 2009 at 20:30 UTC ( [id://802972]=note: print w/replies, xml ) | Need Help?? |
E.g the code I've used for ages for flexible switch parsing, as the original simple arg handling module went against my tastes:
cu & HTH, Peter -- hints may be untested unless stated otherwise; use with caution & understanding.
Update 1: Considering Bloodnok's variant below:
If your Perl's sufficiently recent, use my($_) instead of local to protect your caller while also protecting from anything called functions might do. Also note that I'm using both next and last (loop exit condition) above. If you want a stronger distinction between looping and switching while retaining early loop exiting, you need either a second target label before the while() or set an explicit loop-exit flag variable for testing after the switch block. Simply saying last SWITCH in case of -- when restructuring does introduce a bug and changes semantics of -- to a NOP, with additional problems further down the line for non-option args. Footnotes to my example above:
Non-famous last words: I simply prefer the above solution over given/when and if-cascades for readability and perceived elegance. But given the ascii art readjustment and byte counts, it's not faster to maintain nor that much shorter.
In Section
Seekers of Perl Wisdom
|
|