in reply to getting the name of the module in runtime and calling a function from that module

#!/usr/bin/perl -w use strict; my $path = 'path/to/modlib'; my $module = "MyMod"; my $func = "some_func"; require "$path/$module.pm"; eval "${module}::$func()";
  • Comment on Re: getting the name of the module in runtime and calling a function from that module
  • Download Code

Replies are listed 'Best First'.
Re: Re: getting the name of the module in runtime and calling a function from that module
by krisraman (Novice) on Jun 03, 2002 at 20:45 UTC
    Thanks for your help.I also pass a user defined object as an argument but I seeing the following error messages "cant modify constant item in scalar assignment" "Bareword not allowed whil strict subs in use". So I added "no strict subs" to the code and I could avoid the second message but the first one still persists. The code sample is $obj::Process($Task); (Note: Process is the name of the function which is hardcoded) Any help would be appreciated
      This depends on how exactly you want to call the Process sub: as a class method, an object method or a regular subroutine:
      #!/usr/bin/perl -w use strict; package One; sub ding { print "Ding (".join(',',@_).") called!\n"; } package main; my $classname = "One"; my $obj = bless {},$classname; my $packagename = $classname; $classname->ding('class method'); $obj->ding('object method'); no strict 'refs'; &{$packagename."::ding"}('regular sub');
      Will print:
      Ding (One,class method) called! Ding (One=HASH(0x80fbc2c),object method) called! Ding (regular sub) called!

      -- Joost downtime n. The period during which a system is error-free and immune from user input.