Variable variable name

Curtis Poe cp at
Wed Jul 3 18:48:01 CDT 2002

----- Original Message -----
From: Jason White
To: pdx-Pm-List at
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( ) ?


You don't want to use variable variable names.  Here's a great explanation.

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!

Curtis Poe
Senior Programmer
ONSITE! Technology, Inc.

Taking e-Business and Internet Technology To The Extreme!


More information about the Pdx-pm-list mailing list