Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Print out modules used during runtime?

Reply
Thread Tools

Print out modules used during runtime?

 
 
Omar Zakaria
Guest
Posts: n/a
 
      05-31-2006
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
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      05-31-2006
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

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      05-31-2006
"Paul Lalli" <(E-Mail Removed)> 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/
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      05-31-2006
John Bokma <(E-Mail Removed)> wrote:

> "Paul Lalli" <(E-Mail Removed)> 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/
 
Reply With Quote
 
Omar Zakaria
Guest
Posts: n/a
 
      06-01-2006
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
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      06-03-2006
On Wed, 31 May 2006 15:48:41 -0400, Omar Zakaria <(E-Mail Removed)>
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,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to print out the currently used JAR file path to verify itis using right JAR? markspace Java 2 10-07-2011 06:17 PM
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments