On 8/31/07, Hunter Barrington <[EMAIL PROTECTED]> wrote: > how would i find out what attributes and methods are in a name space? > for example i have an object in my code and im not sure what type it is, > what attributes are associated with it, what methods etc etc how can i > find out. in python there was dir() and type() which was a big help. > anything similar in perl?
If you have an object you can call ref on it to find its class: my $obj = IO::File->new; my $class = ref $obj; #$class is now 'IO::File' There is no one way to implement objects in Perl (besides the fact that they must be blessed), so there is no one way to find all attributes, but the common method of creating objects is to use a blessed hashref. In those cases you can often, but not always since there are many ways to create objects even with blessed hashrefs, get the attributes by saying my @attributes = keys %$obj; To my knowledge there is no way to find what functions are defined in a package but to walk the symbol table. There are a few modules in CPAN that make this easier, but in the end the answer to your question is "read the documentation". Every decent module comes packaged with complete documentation. Try typing perldoc IO::File where IO::File is the name of the class you want info about. The dir function in Python is so useful because Python has a REPL; Perl 5 does not yet have a fully functional REPL*. Perl 6 has a REPL (and interpretor and compiler) named Pugs**, but since Perl 6 is still in development and differs greatly from Perl 5 I cannot recommend using it to learn Perl. * there are a few, but in general I don't think they are true REPLs yet. You can find a list of them here http://use.perl.org/article.pl?sid=07/08/30/1729255 ** http://www.pugscode.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/