Re: How to dynamically generate function name and call it?
- From: "Mumia W. (reading news)" <paduille.4058.mumia.w@xxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 15:52:18 GMT
On 09/27/2006 08:31 AM, Hemant Shah wrote:
Folks,
How do I dynamically generate function and then execute the function?
I have a perl script that is used to drop/create/update database tables.
The script has drop/create/update functions for each table, and I
have if statements to call appropriate functions:
Example:
if ($TableName eq "TRAC")
{
CreateTRACTable();
}
elsif ($TableName eq "TRCO")
{
CreateTRCOTable();
}
and so on. I have similar if statements for drop and update.
Instead of having bunch of if statements, I can put the table
names in a hash and call:
if ($Action eq "Create")
{
Create${TableName}Table():
}
elsif ($Action eq "Drop")
{
Drop${TableName}Table():
}
and so on.
How do I do this?
Thanks.
Use a hash, e.g.:
my %tabledispatch = (
TRAC => \CreateTRACTable,
TRCO => \CreateTRCOTable,
);
....
$tabledispatch{$Action}->();
UNTESTED CODE
--
paduille.4058.mumia.w@xxxxxxxxxxxxx
.
- Prev by Date: using http::recorder
- Next by Date: Re: glob problem: escaped space seems to be significant too (was Re: Problem with glob and filenames containing '[' and ']')
- Previous by thread: Re: How to dynamically generate function name and call it?
- Next by thread: Re: How to dynamically generate function name and call it?
- Index(es):