Print out modules used during runtime?

Discussion in 'Perl Misc' started by Omar Zakaria, May 31, 2006.

  1. Omar Zakaria

    Omar Zakaria Guest

    Hello, all. I was wondering if there's a way, without downloading any
    special modules, or packages, to have a perl script print out the list
    of packages or modules it imported (i.e. anything I "use"'d or
    "require"'d). The script is actually compiled to an .exe, so it can't
    open itself and search for "use". Any ideas? I've tried fiddling with
    package namespaces and reference tables, but I can't seem to find where
    the information is stored, orif its even there.

    As an example, I'd like to know how to get the script below to print out
    "foo/bar.pm, bar/foo.pm" or something along those lines (assuming, of
    course, those modules exist):

    __BEGIN__

    use foo::bar;
    use bar::foo;

    #Insert awesome perl program here

    ....

    __END__


    I'd appreciate any help I could get in the matter.

    --
    Omar Zakaria: crono@cc~
    - "Ne cede malis, sed sempter contra audentior ito." -Virgil
    - "All things are transitory; this too, shall pass." -Buddha
     
    Omar Zakaria, May 31, 2006
    #1
    1. Advertising

  2. Omar Zakaria

    Paul Lalli Guest

    Omar Zakaria wrote:
    > Hello, all. I was wondering if there's a way, without downloading any
    > special modules, or packages, to have a perl script print out the list
    > of packages or modules it imported (i.e. anything I "use"'d or
    > "require"'d).


    %INC is probably what you're looking for. It keeps a list of all
    modules used/required as keys, with the values being the paths to
    those modules. Note, however, that %INC will have not only the modules
    your script specifically used, but also those modules used by a module
    your script used:

    $ perl -e' use CGI; print "$_ => $INC{$_}\n" for keys %INC;'
    warnings/register.pm =>
    /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings/register.pm
    Carp.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Carp.pm
    vars.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/vars.pm
    strict.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/strict.pm
    Exporter.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Exporter.pm
    constant.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/constant.pm
    warnings.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings.pm
    CGI/Util.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI/Util.pm
    overload.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/overload.pm
    CGI.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI.pm

    See perldoc perlvar for more information about %INC.

    Paul Lalli
     
    Paul Lalli, May 31, 2006
    #2
    1. Advertising

  3. Omar Zakaria

    John Bokma Guest

    "Paul Lalli" <> wrote:

    > Omar Zakaria wrote:
    >> Hello, all. I was wondering if there's a way, without downloading any
    >> special modules, or packages, to have a perl script print out the list
    >> of packages or modules it imported (i.e. anything I "use"'d or
    >> "require"'d).

    >
    > %INC is probably what you're looking for. It keeps a list of all
    > modules used/required as keys, with the values being the paths to
    > those modules. Note, however, that %INC will have not only the modules
    > your script specifically used, but also those modules used by a module
    > your script used:
    >
    > $ perl -e' use CGI; print "$_ => $INC{$_}\n" for keys %INC;'
    > warnings/register.pm =>
    > /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings/register.pm
    > Carp.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Carp.pm
    > vars.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/vars.pm
    > strict.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/strict.pm
    > Exporter.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Exporter.pm
    > constant.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/constant.pm
    > warnings.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings.pm
    > CGI/Util.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI/Util.pm
    > overload.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/overload.pm
    > CGI.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI.pm
    >
    > See perldoc perlvar for more information about %INC.


    I think the problem is:

    #Insert awesome perl program here

    and the fact that it's an exe.

    http://www.die.net/doc/linux/man/man1/strace.1.html

    I am sure there is something similar for Windows (tracing which files are
    opened by an exe).

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
     
    John Bokma, May 31, 2006
    #3
  4. Omar Zakaria

    John Bokma Guest

    John Bokma <> wrote:

    > "Paul Lalli" <> wrote:
    >
    >> Omar Zakaria wrote:
    >>> Hello, all. I was wondering if there's a way, without downloading
    >>> any special modules, or packages, to have a perl script print out
    >>> the list of packages or modules it imported (i.e. anything I "use"'d
    >>> or "require"'d).

    >>
    >> %INC is probably what you're looking for. It keeps a list of all
    >> modules used/required as keys, with the values being the paths to
    >> those modules. Note, however, that %INC will have not only the
    >> modules your script specifically used, but also those modules used by
    >> a module your script used:
    >>
    >> $ perl -e' use CGI; print "$_ => $INC{$_}\n" for keys %INC;'
    >> warnings/register.pm =>
    >> /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings/register.pm
    >> Carp.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Carp.pm
    >> vars.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/vars.pm
    >> strict.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/strict.pm
    >> Exporter.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/Exporter.pm
    >> constant.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/constant.pm
    >> warnings.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/warnings.pm
    >> CGI/Util.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI/Util.pm
    >> overload.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/overload.pm
    >> CGI.pm => /opt2/Perl5_8_4/lib/perl5/5.8.4/CGI.pm
    >>
    >> See perldoc perlvar for more information about %INC.

    >
    > I think the problem is:
    >
    > #Insert awesome perl program here
    >
    > and the fact that it's an exe.
    >
    > http://www.die.net/doc/linux/man/man1/strace.1.html
    >
    > I am sure there is something similar for Windows (tracing which files
    > are opened by an exe).


    woops, this might be the dumbest answer of the day :) If it's an exe that
    has all modules also contained in the same file this probably isn't going
    to work.

    --
    John Bokma Freelance software developer
    &
    Experienced Perl programmer: http://castleamber.com/
     
    John Bokma, May 31, 2006
    #4
  5. Omar Zakaria

    Omar Zakaria Guest

    Paul Lalli wrote:
    > %INC is probably what you're looking for. It keeps a list of all
    > modules used/required as keys, with the values being the paths to
    > those modules. Note, however, that %INC will have not only the modules
    > your script specifically used, but also those modules used by a module
    > your script used:


    Perfect. Thanks a million.

    --
    Omar Zakaria: crono@cc~
    - "Ne cede malis, sed sempter contra audentior ito." -Virgil
    - "All things are transitory; this too, shall pass." -Buddha
     
    Omar Zakaria, Jun 1, 2006
    #5
  6. On Wed, 31 May 2006 15:48:41 -0400, Omar Zakaria <>
    wrote:

    >Hello, all. I was wondering if there's a way, without downloading any
    >special modules, or packages, to have a perl script print out the list
    >of packages or modules it imported (i.e. anything I "use"'d or
    >"require"'d). The script is actually compiled to an .exe, so it can't


    I *like* to play tricks with code in @INC:

    C:\WINDOWS>perl -le "use lib sub { !warn pop }; use CGI"
    CGI.pm at -e line 1.
    Carp.pm at -e line 1.
    Exporter.pm at -e line 1.
    CGI/Util.pm at -e line 1.
    vars.pm at -e line 1.
    warnings/register.pm at -e line 1.
    warnings.pm at -e line 1.
    constant.pm at -e line 1.
    overload.pm at -e line 1.

    (DISCLAIMER: optimized for brevity, as I've broken my left arm and I'm
    currently waiting for it to be surgically operated!)

    Of course this kind of trick is more complex than plainly inspecting
    %INC and in this case it has no advantage over the latter. You may
    like it if you are interested in the order in which modules are
    searched or if you want your report for selected C<use> statements
    only.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jun 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    1,043
  2. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    399
    David Cournapeau
    Dec 30, 2008
  3. markspace
    Replies:
    2
    Views:
    496
    markspace
    Oct 7, 2011
  4. Arne Vajhøj
    Replies:
    0
    Views:
    745
    Arne Vajhøj
    Nov 6, 2011
  5. iMath
    Replies:
    2
    Views:
    168
    Peter Otten
    Dec 26, 2012
Loading...

Share This Page