Variable variable name
Curtis Poe
cp at onsitetech.com
Wed Jul 3 18:48:01 CDT 2002
----- Original Message -----
From: Jason White
To: pdx-Pm-List at pm.org
Sent: Wednesday, July 03, 2002 4:14 PM
Subject: Variable variable name
Here is some code.
my $functionToCall = "foo";
???????( )
sub foo(){
print "FOO!\n";
}
How can I use the variable $functionToCall to replace ??????? with foo( ) ?
---------------------
Jason,
You don't want to use variable variable names. Here's a great explanation.
http://perl.plover.com/varvarname.html
http://perl.plover.com/varvarname2.html
http://perl.plover.com/varvarname3.html
As for what you want to do, there are several solutions. How about a
dispatch table?
my %dispatch_to =
(
foo => \&foo,
bar => \&bar,
baz => \&baz
);
# later
if ( exists $dispatch_to{ $some_func } )
{
$dispatch_to{ $some_func }->( @args );
}
If you're not sure what the above does, read "perldoc perlreftut".
Hope this helps!
--
Cheers,
Curtis Poe
Senior Programmer
ONSITE! Technology, Inc.
www.onsitetech.com
503-233-1418
Taking e-Business and Internet Technology To The Extreme!
TIMTOWTDI
More information about the Pdx-pm-list
mailing list