Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Nested Dispatch Tables?

by Spidy (Chaplain)
on Mar 24, 2008 at 16:22 UTC ( [id://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.

    Julio

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://675929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-03-29 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found