On Sat, Mar 03, 2012 at 01:51:28PM -0500, Steve Bertrand wrote:
> Hi all,
> 
> I have a need to examine and manipulate certain aspects of a class
> symbol table. I can do this:
> 
> my $dog = Animal->new();
> foreach my $entry ( keys %Animal:: ){
>     ...
> }
> 
> ...but what I'd like to do is dereference the object itself to get
> the class, as there will be times I won't know what class an object
> belongs to. Here is some pseudocode of what I'm trying
> unsuccessfully to achieve:
> 
> my $dog = Animal->new();
> foreach my $entry ( keys %{ ref $dog }:: ){
>     ...
> }
> 
> Is there a proper way to do this that someone could point out?

no strict "refs";
foreach my $entry ( keys %{ ref($dog) . "::" })

But why?  If you really need class introspection then OK, but for
general programming you should follow the API as documented.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to