Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python dir equivalent in perl?

Tags:

python

perl

The dir command in Python 2.7.x lists all accessible 'symbols' from a module. Is there an equivalent in Perl 5.x to list all accessible 'symbols' from a package?

like image 831
Konstantin Burlachenko Avatar asked Sep 12 '14 13:09

Konstantin Burlachenko


3 Answers

For package h,

package h; 
our $r; 

use Data::Dumper;
print Dumper \%h::;
like image 22
mpapec Avatar answered Nov 05 '22 03:11

mpapec


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 symbol has those a variable of the specified type associated with it.

like image 135
ikegami Avatar answered Nov 05 '22 03:11

ikegami


You can do it all yourself by rummaging around in the package's symbol table. But Devel::Symdump makes it all a lot easier.

like image 38
Dave Cross Avatar answered Nov 05 '22 03:11

Dave Cross