On Wed, 5 Jan 2005, Charles K. Clarkson wrote: > Christopher Spears <[EMAIL PROTECTED]> wrote: > > : I heard a lot of people dislike goto. Why? When > : should I use this command? > > There are three forms of this statement. Each is > discussed in the 'perlfunc' reference to 'goto'. Have > you read that document? > > 'goto' is usually used as an advanced tool. It is > seldom needed in well designed algorithms. In [brief] defense of GOTO, for some programming it is essential. Assembly language programming, for example.
The problem is that if not managed carefully, it can quickly lead to "spagetti code": a mash of lines of execution that is nearly impossible to debug. In general, a good rule of thumb is to think carefully about any situation where a GOTO seems like a necessary. In a lot of cases, there will be some clearer way to accomplish the same result -- often in the form of calling a subroutine or jumping out of a loop with a `next FOO` line, or something to that effect. If you think you need it but aren't sure, you can always ask the list for a second opinion :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>