Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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.


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


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

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!
  • 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, 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2018-03-21 14:06 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (267 votes). Check out past polls.