Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Re: Re: passing arguments in a dispatch table

by CharlesClarkson (Curate)
on Apr 29, 2002 at 06:06 UTC ( #162775=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: passing arguments in a dispatch table
in thread passing arguments in a dispatch table

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.

Charles K. Clarkson
Clarkson Energy Homes, Inc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://162775]
[Happy-the-monk]: Discipulus: thanks! So in Ascii "CTRL" + "ARROW UP" + "<-- -->"?
[hippo]: On my tab key the left pointing arrow is directly above the right-pointing arrow (and they are each pointing at a vertical line). It's a UK keyboard.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-11-21 10:14 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.