[plug] Perl Query...

Kim Covil kimc at zydeco.ned.dem.csiro.au
Wed Jan 31 16:23:11 WST 2001


> 
> Kim Covil wrote:
> > 
> > > Any ideas??
> > 
> > my $obj = new Class;
> 
> But I don't want to go around creating objects willy nilly. I just want to call
> a function in a Module. Heck, the Module::Function syntax would do - but I
> still need to arbitarily specify the fn.
> 
> > if ($obj->can($bink)) {
> >         $obj->$bink(@args);
> 
> This syntax seems to work fine where you have an object, but not when you have
> a module. ie; doing Class->$bink(@args) doesn't seem to work. And that's what
> I'm after...

Class->$bink(@args) works for me... but remember the first argument that 
is given to the sub is "Class" where it would normally be $obj in the 
example I gave...

Here was my quick test:

--- file MyTest.p ---
package MyTest;
 
sub blah {
        print "In blah called with: ".join(',', at _);
}
 
print "Loaded MyTest\n";
 
1;                                                                              

--- file test.pl ---
#!/usr/bin/perl
use MyTest;
 
my $func = "blah";
 
MyTest->$func("Hello", "there");                                                

--- running the above example ---
> perl test.pl
Loaded MyTest
In blah called with: MyTest,Hello,there                                         >


Cheers

Kim

-- 
====================================================================== 
Kim Covil - CSIRO Exploration & Mining   E-mail: kimc at ned.dem.csiro.au
            PO Box 437, Nedlands,        Tel: +61 8 9284 8425   ,-_!\
            Western Australia  6009      Fax: +61 8 9389 1906  /     \
                                                               *_,-._/
=================================================================== v 
   Please direct all personal e-mail to kimbotha at covil.com.au



More information about the plug mailing list