...every construct that can be written with a goto can be written more clearly without one.
Try to rewrite
TheDamian's
Switch without the key
goto $__; I dare you. Until you can do it, you haven't demonstrated that everything that can be written with a
goto can be written without one (let alone written more clearly).
More generally read the thread at
(Ovid) Re: Re (tilly) 2: Paradigm Shift - Don't use strict to find out my opinion on when it is justified.
The paper of Knuth's that was referred to there gives several other good reasons to use
goto in at least some languages. Most of them boil down to the observation that there are many algorithms that can more efficiently be written with
goto than without. At least in some languages.
But not in Perl. A theorem that Knuth refers to from the literature is that any flow of control that can be achieved with
goto can be achieved with nested loops and named loop control. Therefore in Perl you need extraordinary reasons to really need
goto. (
TheDamian had an example that I believe to be exactly that extraordinary.)
Incidentally at
Re: Re (tilly) 4: Paradigm Shift - when to use goto you will find a pre-processor macro from
TheDamian showing you how to get named loops in C++. It uses
goto, but considering that its purpose is to replace
gotos that people write by hand with a more structured alternative, you may appreciate it.
UPDATE: I just checked. It seems that
TheDamian renamed $__ at some point. He now has labels named "C_A_S_E_$casecounter" instead.
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.