in reply to Re: How do I interpolate package name in a fully qualified name?
in thread How do I interpolate package name in a fully qualified name?

... isn't this what objects are for?

Second that. (And strictures don't have to be turned off.)

>perl -wMstrict -le "{ package Zelda; sub type { shift; return 'prince'; } } ;; { package Mario; sub type { shift; return 'hero'; } } ;; { package Kupa; sub type { shift; return 'villan'; } } ;; foreach my $pkg (qw/Zelda Mario Kupa/) { printf qq{$pkg is a %s \n}, $pkg->type; } " Zelda is a prince Mario is a hero Kupa is a villan

Update: Note: The  shift; in each of the
    sub type { shift;  return 'whatever'; }
subroutine definitions was intended only to point up the fact that a string representing the package (or class) name is implicitly passed as the first argument to any class method (which this subroutine is). Because the method does not interact with the argument list in any way, it is not needed.

Replies are listed 'Best First'.
Re^3: How do I interpolate package name in a fully qualified name?
by AGhoulDoingPerl (Sexton) on Apr 22, 2011 at 14:37 UTC
    OK, Both of them are working. Thank you.