Re: How to dynamically generate function name and call it?
- From: "DJ Stunks" <DJStunks@xxxxxxxxx>
- Date: 27 Sep 2006 16:33:59 -0700
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.
Are your Create{ xxxx }Table and Drop{ xxxx }Table routines so
different for various xxxx's that you have to have completely different
subs for each distinct create, drop and xxx combination?
I'm sure you could simplify to
sub create_table {
my ($xxxx) = shift
# create as necessary
}
or even
sub alter_table {
my ($action, $xxxx) = @_;
# create as necessary if $action eq 'create'
# drop as necessary if $action eq 'drop'
}
-jp
.
- Prev by Date: Re: Limit FORM mailer submissions to 5 on website, then pause until reviewed by webmaster
- Next by Date: FAQ 3.1 How do I do (anything)?
- Previous by thread: Re: How to dynamically generate function name and call it?
- Next by thread: Free ODBC driver for UNIX
- Index(es):
Relevant Pages
|