|laziness, impatience, and hubris|
Would you use 'goto' here?by Ovid (Cardinal)
|on Dec 06, 2001 at 03:06 UTC||Need Help??|
Ovid has asked for the
wisdom of the Perl Monks concerning the following question:
Recently, I asked tilly under what circumstances he would use a goto, since I have only used it once in all of my Perl programming. Oddly enough, I've found a circumstance under which it seems perfectly reasonable, but somehow, it doesn't feel quite right and I'd like to hear pros and cons about this.
In my HTML forms, I have "action" and "type" parameters. In the code snippet below, "action" equals "edit" and "type" equals "product". This allows someone to, duh, edit a product. However, if an office ID is sent, then I know that they are actually editing product information for an office. Since subroutine calls are made based upon a dispatch table that checks the action and type, calls to edit an product and edit an office product automatically go to the same subroutine (they are the same permission, as defined in the business rules). As a result, I considered using a goto to transfer control to the correct subroutine if I see that they're trying to edit a product for an office:
I could simply use the following:
I have at least nine functions that this decision will affect and I know that this seems really nitpicky, but I was wondering, as a matter of style, what people would prefer. I have some error reporting which checks the caller and I think that the goto would be a cleaner solution.
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.stats.