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

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
  • Comment on Re: Re: getting the name of the module in runtime and calling a function from that module

Replies are listed 'Best First'.
Calling subs/methods in $variable packages
by Joost (Canon) on Jun 04, 2002 at 14:04 UTC
    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.