Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have two problems with this aproach

  1. $dispatch is not passed to process, making it a global variable. Just what I'd like to get my readers to avoid. Changing the code to pass $dispatch skips a step. As I said: "Later, $dispatch will be passed to process() as well" [emphasis added]. Your getting ahead of the lesson. (Stop being a teacher's pet.)

  2. You're not passing the args directly to the appropriate sub. You're passing the arguments to every subroutine. Let me illustrate the point with a different example.

    my $dispatch = { 1 => sub { return search_menu($current_user) }, 2 => sub { return edit_name($book) }, 3 => sub { return add_entry($book) }, 4 => sub { return delete_entry($book) }, 5 => sub { return save_default($current_user) }, 6 => \sub{ print "Goodbye!\n"; die; }, e => \sub{ print "Goodbye!\n"; die; }, }; &{ $dispatch->{ $choice } };

    Here, the arguments are defined in the dispatch table. I would like to help my readers think in broad terms instead of solving just this one problem. Your solution works fine, but more than 1400 people view these posts and most don't ask questions. My goal is to reach a wide audience with code examples and explanations that can be applied to other problems as well.

It would seem I'm better at anwering questions than at asking them. Thank you for your reply.


HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.

In reply to Re: Re: Re: Re: passing arguments in a dispatch table by CharlesClarkson
in thread passing arguments in a dispatch table by CharlesClarkson

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found