http://www.perlmonks.org?node_id=194764


in reply to dispatch table of functions and arguments

Surely using positional parameters causes serious braindamage :-)

A solution could be using named parameters (a hash, I mean). For example, parameters for ClickInterval and Exposure could be respectively:

%param = ( firstClick => 12345, secondClick => 21345) ;

and

%param = ( 'value' => 911 ) ; # call for help on "Exposure"

Once you compose the %param hash someway, you could end up your code with a simple call:

my @res = $function_etc_etc{$a_function}->(%params) ;

and each sub will get only the parameters it deserves :-)

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->made($love) ;
}

Replies are listed 'Best First'.
Re: Re: dispatch table of functions and arguments
by Sihal (Pilgrim) on Sep 03, 2002 at 14:26 UTC
    YES i understand that. however, what would be really nice, is if I could build a dispatch table for the parameters as well, and then give a value to the params somewhere in my code and then use it whenever I please. don't know if I clear
      fglock your solution still isn't quite like what I imagined : imaghine I have 3 parameters $toto, $titi, $tata.
      I'm inside a while(){} and I want to call some funcs of my dispatch table with either $toto, $titi, or $tata ( depending of the type of data i'm fed) but keeping in mind that the values of $titi, $toto, $tata change at every iteration (because of the data i'm fed) ..... is it possible?
Re: Re: dispatch table of functions and arguments
by Sihal (Pilgrim) on Sep 03, 2002 at 14:20 UTC
    thanx a lot for your replies but I still fail to understand how to pass the args.... oki I'll re read the node
Re: Re: dispatch table of functions and arguments
by Sihal (Pilgrim) on Sep 03, 2002 at 15:07 UTC
    In fact what I currently do is kinda the same as you suiggest, but i have to pass around in a hash of 15 arguments ( and then the subs figure out wich ones they need ) so it's kinda a waste, which is why I want to refine this mechanism