(Sorry, Uri, meant to reply to the list...) On Thu, Apr 14, 2011 at 10:47 AM, Uri Guttman <u...@stemsystems.com> wrote: > then you don't know how to code well in c. it may not be as > nice as perl for some flow control things but goto is never > needed in c either. i have seen it used and there are always > better ways to code it than with gotos. you just need to know > other techniques and none of them are convoluted. a better > design helps too.
I often use gotos in C for error handling within a function. If you're allocating resources and something later on fails then you usually want (or need) to clean up those resources before returning. I've seen a lot of people duplicate the same cleanup code over and over again. I hate doing that. Goto makes it much cleaner. Just because you can make spaghetti with goto doesn't mean goto always has to make spaghetti. You do need to be careful though and assess any given situation carefully. That said, I think the clean uses for goto in Perl are probably much less common, if they exist at all. Perl has plenty of flow control features to probably eliminate any advantages that goto might have had. You should never look for opportunities to use goto in any language though. You should understand how goto works so that you can recognize where it /might/ benefit the code. Just be careful to use it for the right reasons. -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/