[comp.lang.perl] Jump tables?

brister@decwrl.dec.com (James Brister) (04/20/91)

Is there an elegant way (other than a massive if-then-else) to do the
following in Perl?

	struct { char *name ;
		 int (*function)() ;
        } jump_table [] = {{"Hello", greeting_fn},
			   {"Bye", exit_fn},
			   {NULL, NULL}}

	i = 0 ;
	while (jump_table [i].name && strcmp (jump_table [i].name,command))
		i++ ;
	if (jump_table [i].function)
		(*jump_table[i].function)() ;


i.e. setup a function name/function mapping so I can find the function name
and then call the function.

I've got the Camel Book, if you know of a referrence in there. 

Thanks

James
--
James Brister                                           brister@decwrl.dec.com
DEC WSL., Palo Alto, CA                 {uunet,pacbell,pyramid}!decwrl!brister
"Old mathematicians never die; they just lose some of their functions."