Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: dispatch table of functions and arguments

by bronto (Priest)
on Sep 03, 2002 at 13:43 UTC ( #194764=note: print w/replies, xml ) Need Help??

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) ;


%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 :-)


# Another Perl edition of a song:
# The End, by The Beatles
  $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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194764]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-01-23 11:07 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (192 votes). Check out past polls.