Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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:

sub edit_product { my ( $query, $db, $mod, $sec ) = @_; if ( $query->param( 'officeID' ) ) { goto &edit_office_product }; $query->delete( 'action' ); $query->delete( 'type' ); if ( $query->param ) { # they've submitted the form } else { # send them to the form } }

I could simply use the following:

if ( $query->param( 'officeID' ) ) { return edit_office_product( @_ ); }

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.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

stats.


In reply to Would you use 'goto' here? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (8)
    As of 2014-12-20 12:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls