Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

List of loaded subroutines

by slloyd (Hermit)
on Jul 28, 2005 at 07:04 UTC ( #478852=perlquestion: print w/replies, xml ) Need Help??

slloyd has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to figure out a way to print the list of subroutines that are loaded via use and require of the currently running script. Is this possible?
use strict; use Win32; require '/'; # print a list of subroutines that are currently loaded ???

Replies are listed 'Best First'.
Re: List of loaded subroutines
by davido (Cardinal) on Jul 28, 2005 at 07:19 UTC

    You could try the B::Xref module:

    perl -MO=Xref

    For non-trivial scripts the output can be quite verbose. Fortunately, the POD for the module mentions the -o option which allows you to dump the output to a file instead of the screen.


Re: List of loaded subroutines
by xdg (Monsignor) on Jul 28, 2005 at 11:20 UTC

    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.)


    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.

Re: List of loaded subroutines
by Fang (Pilgrim) on Jul 28, 2005 at 07:14 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://478852]
Approved by monkfan
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-11-29 00:36 GMT
Find Nodes?
    Voting Booth?