in reply to Automating dispatch tables

Nice. However, I don't like the package main, because you can never be certain that that's the original package name (as a code practice, not in this example, obviously).

I would have written this as:

{ package dispatch; sub foo {} sub bar {} sub baz {} sub qux {} } if( my $ref = dispatch->can($method) ) { $ref->(); }
This automatically returns the package to the original package after the definition of the dispatch table.

Liz

Replies are listed 'Best First'.
Re: Re: Automating dispatch tables
by BUU (Prior) on Apr 16, 2004 at 07:53 UTC
    Ah. Clever. I just assumed you would know what package you should be returning to :)