Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Would you use 'goto' here?

by demerphq (Chancellor)
on Dec 06, 2001 at 15:51 UTC ( [id://129888]=note: print w/replies, xml ) Need Help??


in reply to Would you use 'goto' here?

Considering that one of your objectives is to control what caller() reports then I think that using goto &sub is prefectly legitimate, after all that was the very reason why it is included in the language at all.

However to address the readability/maintainability of your code I think that perhaps you are taking the wrong approach, a slight change in methodology would IMO make it much more clear. Instead of having one sub that handles both the forwarding and the processing of one case, use one sub that forwards to two others. Give it a nice convienient, obvious name and presto, you get the magic with the readability:

sub edit_product_disptacher { # uses magic goto to fool caller() my ($query)=@_; if ( $query->param( 'officeID' ) ) { goto &edit_office_product } else { goto &edit_product } }
It seems to me that documenting that you are using a magic goto and why should be sufficient for and support programmer. It tells them what you are doing (so they can easily find the docmentation) and why, and once they read the docs they will (er, should :-) understand perfectly whats going on.

Yves / DeMerphq
--
This space for rent.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://129888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (None)
    As of 2024-04-19 00:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found