http://www.perlmonks.org?node_id=1009063


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(...);

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