Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Using $variable in place of "Method" in Module::Submodule::Method( @args )

by Joost (Canon)
on Aug 23, 2006 at 19:25 UTC ( [id://569182]=note: print w/replies, xml ) Need Help??


in reply to Using $variable in place of "Method" in Module::Submodule::Method( @args )

PackageName::subname() is not how you call a method. That's how you call a normal subroutine in package PackageName.

Anyway...

# call a method by name. # this works for real methods only. my $method = "some_method"; ClassName->$method(@arguments); $object->$method(@arguments); # or .... # get a subroutine reference and call that # this works provided you call it the right way my $subref = Package->can("some_method"); # call subref as class method Package->$subref(@args); # call subref as object method $object->$subref(@args); # call subref as normal subroutine $subref->(@args);

The last construct is probably what you need.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://569182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found