Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Dynamic Package Name & Subroutine Call

by ikegami (Pope)
on Dec 16, 2012 at 13:57 UTC ( #1009063=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Dynamic Package Name & Subroutine Call
in thread Dynamic Package Name & Subroutine Call

can should be used for methods and only for methods, so that should be

my $full_pkg = "Test::".$pkg; my $hello = $full_pkg->can('hello'); $full_pkg->$hello(...); # Or: $hello->($full_pkg, ...);

which simplifies to:

my $full_pkg = "Test::".$pkg; $full_pkg->hello(...);

You don't even need can if the method name is variable.

$full_pkg->$method_name(...);


Comment on Re^3: Dynamic Package Name & Subroutine Call
Select or Download Code
Replies are listed 'Best First'.
Re^4: Dynamic Package Name & Subroutine Call
by Anonymous Monk on Dec 17, 2012 at 08:51 UTC

    can should be used for methods and only for methods

    that boat has sailed a long time ago :)

      That makes no sense. This isn't a change; can has never done the right thing for non-methods.

        sure it has :)

        $ perl -le " sub fudge { 42 } print main->can(q/fudge/)->() " 42

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2015-07-31 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (277 votes), past polls