Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Nested Dispatch Tables?

by Spidy (Chaplain)
on Mar 24, 2008 at 16:22 UTC ( #675929=note: print w/replies, xml ) Need Help??

in reply to Re: Nested Dispatch Tables?
in thread Nested Dispatch Tables?

That sort of sounds like what I'm looking for. In the end, I want to be able to make a call like $actions->{$type}->{$action}->();, or however you'd accomplish the same thing(if that makes any sense) in actually valid Perl.

This isn't the most elegant of solutions, but would building my two dispatch tables(something like %objects and %containers) and then storing them into an %actions hash as references work?

Replies are listed 'Best First'.
Re^3: Nested Dispatch Tables?
by dirving (Friar) on Mar 24, 2008 at 19:23 UTC
    The code you give there is valid Perl. If you built a structure using something like the following you would be able to use it just like that:
    my $actions = { first_action => { type1 => \&some_function, another_type => \&another_function }, second_action => { another_type => \&function, yet_another_type => \&something, }, };
    -- David Irving
Re^3: Nested Dispatch Tables?
by jfraire (Beadle) on Mar 25, 2008 at 01:26 UTC

    Altough you have said that you are not using object-oriented techniques, what chromatic gave you reads like this: $container->action() or $object->action() which looks quite elegant to me. Instead of dispatch tables, you would have two classes and then choose what kind of object to create depending on your $type variable. Then, for each class, you would have your special $actions (methods). That way your main code is the same for both containers and objects, and their differences are hidden in their own space.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-02-19 14:15 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (264 votes). Check out past polls.