in reply to Re: Dynamic Package Name & Subroutine Call
in thread Dynamic Package Name & Subroutine Call
An alternative to no strict 'refs' would be:
foreach my $pkg ( @pkgs ) { my $hello = "Test::$pkg"->can('hello'); $hello->() if $hello; }
... because can returns a coderef. In the case of packages that have inheritance (@ISA) this will act slightly differently to &{'Test::' . $pkg . '::hello'}().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dynamic Package Name & Subroutine Call
by ikegami (Patriarch) on Dec 16, 2012 at 13:57 UTC | |
by Anonymous Monk on Dec 17, 2012 at 08:51 UTC | |
by ikegami (Patriarch) on Dec 17, 2012 at 13:06 UTC | |
by Anonymous Monk on Dec 17, 2012 at 13:10 UTC | |
by ikegami (Patriarch) on Dec 19, 2012 at 12:46 UTC | |
|