Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!spool.mu.edu!news.nd.edu!mentor.cc.purdue.edu!purdue!haven!decuac!pa.dec.com!decwrl!brister From: brister@decwrl.dec.com (James Brister) Newsgroups: comp.lang.perl Subject: Jump tables? Message-ID: Date: 19 Apr 91 22:50:26 GMT Sender: news@pa.dec.com (News) Organization: DEC Western Software Lab Lines: 28 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."