in reply to Writing Plugin-Able perl scripts

Okay, very cool from what I've seen above I've pretty much written the plugin system as far as having the methods/variables/data I need available to the central App, thanks SO much for the help

Now another related question/solution. Since most of this runs as sort of an "Event Loop" I've written an initialization routine for each module so that gets called when it's first included.

what I'd like to do is have the available functions/necessary calls to be put into a hash or list where they can be called when their needed, basically the equivalent of having a pointer to a function in C, can I do something like:

foreach (keys %FunctionHash) { $return = &callMySub($_); # Do somethign with return here }
or would there be a better method. Basically all of the modules export the same functions, but since each plugin is configurable there may be some that the end user (myself) may not wish to execute.....

Note: I know I could make this much simpler just by saying you have one function that does everythign and if you get more data then you want, tough cookies. However management doesn't like that method....

Replies are listed 'Best First'.
Re: Re: Writing Plugin-Able perl scripts
by theorbtwo (Prior) on Sep 03, 2002 at 02:12 UTC

    To call a subref, use $subref->(args).

    Note, however, that the keys of a hash are always plain strings; they can't be references. If you try to use a ref, you'll end up getting the stringified version, which can never be reconstructed into a real reference. (Well, that isn't strictly true, but is close enough.)

    So what you probably want to say is more like:

    foreach (values %FunctionHash) { $return = $_->($data); }


    Confession: It does an Immortal Body good.

      $return = &{$_->($data)};

      is  & optional here?

      update: do you mean  &{$_{$data}} or even  &{$data{$_}} ? I think the last one looks better.