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'}().
In reply to Re^2: Dynamic Package Name & Subroutine Call
by tobyink
in thread Dynamic Package Name & Subroutine Call
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |