Python dir equivalent in perl?

The command dirin Python 2.7.x lists all the available "characters" from a module. Is there any equivalent in Perl 5.x to list all the available "characters" from a package?

+4
source share
4 answers
say for sort keys %Foo::Bar::;

you can use

*Foo::Bar::sym{SCALAR}
*Foo::Bar::sym{ARRAY}
*Foo::Bar::sym{HASH}
etc

to see if the character has those variables of the specified type associated with it.

+5
source

You can do it yourself by tearing in the package symbol table. But Devel :: Symdump simplifies things.

+3
source

h,

package h; 
our $r; 

use Data::Dumper;
print Dumper \%h::;
+1

Devel::Symdump . , :

$ perl -M'Devel::Symdump' -e 'print(Devel::Symdump->new("Devel::Symdump")->as_string)'
arrays

functions
    Devel::Symdump::AUTOLOAD
    Devel::Symdump::DESTROY
    Devel::Symdump::_doit
    Devel::Symdump::_inh_tree
    Devel::Symdump::_isa_tree
    Devel::Symdump::_partdump
    Devel::Symdump::_symdump
    Devel::Symdump::as_HTML
    Devel::Symdump::as_string
    Devel::Symdump::diff
    Devel::Symdump::inh_tree
    Devel::Symdump::isa_tree
    Devel::Symdump::new
    Devel::Symdump::rnew
hashes

ios
    Devel::Symdump::ENTRY
packages

scalars
    Devel::Symdump::AUTOLOAD
    Devel::Symdump::BEGIN
    Devel::Symdump::DESTROY
    Devel::Symdump::Defaults
    Devel::Symdump::ENTRY
    Devel::Symdump::MAX_RECURSION
    Devel::Symdump::VERSION
    Devel::Symdump::_doit
    Devel::Symdump::_inh_tree
    Devel::Symdump::_isa_tree
    Devel::Symdump::_partdump
    Devel::Symdump::_symdump
    Devel::Symdump::as_HTML
    Devel::Symdump::as_string
    Devel::Symdump::diff
    Devel::Symdump::import
    Devel::Symdump::inh_tree
    Devel::Symdump::isa_tree
    Devel::Symdump::new
    Devel::Symdump::rnew
unknowns

HTML (, ..).

Please note, however, that AUTOLOADed characters are not reset if they were not loaded. If you want to see all the available characters, you need to look at the documentation and / or source code.

0
source

All Articles