in reply to List of loaded subroutines

You can look at the symbol table of a package for code entries. E.g. for "main"

no strict 'refs'; for ( keys %{"main::"} ) { print "$_\n" if defined *{"main::$_"}{CODE}; }

If you want to know subroutines of everything loaded, then you can use the %INC hash, convert back to module names, and search through all of them for subroutines:

my @subs; for my $mod ( keys %INC ) { $mod =~ s!/!::!g; $mod =~ s/.pm$/::/; { no strict 'refs'; for ( keys %{$mod} ) { push @subs, $mod . $_ if defined *{$mod . $_}{CODE}; } } } print "$_\n" for @subs;

(Note that this won't find subroutines that are explicitely loaded into a package that isn't named the same as the file that was required or used.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: List of loaded subroutines
by slloyd (Hermit) on Jul 29, 2005 at 03:56 UTC