--- Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote:
> On Jul 3, John Edwards said:
> 
> >It's messy and relies on you naming you subroutines to match the
> static data
> >stored in %funcs. It will introduce more possible points of failure
> in the
> >code, make it harder to debug and maintain. Unless you've got a
> really good
> >reason why you need to do this, I'd suggest you don't.
> 
> I *strongly* disagree.  If you've never used a dispatch table, you're
> not aware of the power and simplicity they bring.
> 
>   %actions = (
>     login => \&welcome,
>     authent => \&checkpass,
>     logout => \&cleanup,
>     request => \&servepage,
>   );
> 
>   if (my $function = $actions{$state}) { $function->(@_) }
>   else { die "unknown state '$state'" }
> 
> Dispatch tables (hashes of function references) are a Larry-send. ;)

lol ---
you can also build anonymous functions right into the table, if that
helps you maintain them more easily. 

   %funcs = (
     this => sub { 
                 # code for "this"
             },
     that => sub { 
                 # code for "that"
             },
     foo  => sub { 
                 # code for "foo"
             },
     bar  => sub { 
                 # code for "bar"
             },
   );

   my $key = &somethingThatAssignsTheLookupKey();
   $func{$key}->(@funcArgs);



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Reply via email to