... 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.
In reply to Re^2: How do I interpolate package name in a fully qualified name?
by AnomalousMonk
in thread How do I interpolate package name in a fully qualified name?
by AGhoulDoingPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |