Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
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 wandering the Monastery: (10)
As of 2014-07-25 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (169 votes), past polls