Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Installed Modules

by xenchu (Friar)
on Dec 07, 2003 at 04:07 UTC ( #312850=perlquestion: print w/replies, xml ) Need Help??

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

I know I am overlooking something obvious. I wrote this tiny program to learn what modules are installed on my machine:

use strict; use ExtUtils::Installed; my $module; my $inst = ExtUtils::Installed->new(); my (@modules) = $inst->modules(); foreach $module (@modules) { print "$module \n"; }
When I run it, all I get back is the word Perl. Anyone want to stop laughing long enough to tell me the mistake I am making?

xenchu

Update:Well, actually I was expecting to see the Perl source distribution modules. According to the perldoc ExtUtils::Installed it is supposed to print all the modules on my system. I will try another way and if it works I will put it here. Thanks to both of you.

Update2:OK, here is the code I came up with:

use strict; use File::Find; my @files; find sub { push @files, $File::Find::name if -f _ && /\.pm$ +/ }, @INC; my ($mod, $hash, $name); my (@results, %hash, @results2); @results = map {/.+\/.+\/(.*).pm$/} @files; $hash{$_}++ foreach (@results); foreach (sort keys %hash) { print "$_.pm \n"; }
I am sure that there is a better way to do this. And btw, I have only the standard modules on this machine, a condition I plan to rectify. Anyway, thanks again.



****sigfilesigfilesigfilesigfilesigfilesigfilesigfilesigfile

Perl has one Great Advantage and one Great Disadvantage:

It is very easy to write a complex and powerful program in three lines of code.

********************************************

The Needs of the World and my Talents run parallel to infinity.

Replies are listed 'Best First'.
Re: Installed Modules
by Zaxo (Archbishop) on Dec 07, 2003 at 04:42 UTC

    Your code works for me. Here is a command line version which doesn't differ in any important way, $ perl -MExtUtils::Installed -e'my $inst = ExtUtils::Installed->new(); print $_, $/ for $inst->modules' That prints the correct list, which includes "Perl" as one element. I'm at a loss to say why you don't get more. You seem to be finding the ExtUtils::Installed module ok.

    After Compline,
    Zaxo

Re: Installed Modules
by ysth (Canon) on Dec 07, 2003 at 05:20 UTC
    It also works for me. It doesn't include any modules that are in the perl source distribution; were you expecting to see those? There is a list in perlmodlib.pod.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://312850]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-06-23 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (118 votes). Check out past polls.

    Notices?