Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any way to dynamically call a subroutine 2

Status
Not open for further replies.

cdlvj

MIS
Nov 18, 2003
676
0
0
US
Listers,

I have a perl event ftp processor, which is driven by a .ini file.

Is there any way to call a function based on what is defined in the .ini file.

ie.

[txt]
destination=ftp.someserver.com
preprocess=foo
[dat]
destination=ftp.somewhereelse.com



Would like to have a line if preprocess is defined, to call the foo function.

Do not want to have a large if condition test for each possibility.
 
use a hash that is a reference to subs:

Code:
my %coms = {
   foo => \&foo,
   bar => \&bar,
}






------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
You can also store the content of field [tt]preprocess[/tt] into a variable, then:
Code:
$preprocess='foo';
$returnvalue=&$preprocess(@args)if defined&$preprocess;
The [tt]if defined[/tt] works for both conditions, when $preprocess is [tt]undef[/tt] or null, and when [tt]sub foo[/tt] is not defined.

prex1
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top