Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List of available Perl modules 3

Status
Not open for further replies.

wapboy

Technical User
Oct 26, 2002
13
0
0
GB
Is there a way of listing what PERL modules are available on my Server. A PERL function similar to PHP's phpinfo() is what I'm looking for I guess

Thanks

Paul
 
from the command line: perl -e 'print "@INC";'


Kind Regards
Duncan
 
Thanks for the quick response. I'm on a shared server so haven't got access to the command line - can I do the suggested command in a script?

Paul
 
Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
foreach (@INC) {
  print "$_<br>\n";
}

HTH
--Paul
 
pour un affichage plus lisible
[tt]
print join("\n",@INC)
[/tt]

Jean Pierre.
 
Isn't that just going to find all the places modules can exist? How about something like this:
Code:
use CGI qw/header/;
use File::Find;

print header();
find(\&wanted, @INC);

sub wanted
{
        /\.pm/ || return;
        my $module = $File::Find::name;

        $module =~ s|^\Q$_\E/(.+)\.pm$|$1| for(sort {length $b <=> length $a } @INC);
        $module =~ s|/|::|g;
        print "$module<br />\n";
}

________________________________________
Andrew - Perl Monkey
 
what does this bit do?

$module =~ s|^\Q$_\E/(.+)\.pm$|$1| for(sort {length $b <=> length $a } @INC);

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Believe it or not, this is actually the example in the File::Find::Rule docs:
Code:
# find all the .pm files in @INC
my @files = File::Find::Rule->file()
                            ->name( '*.pm' )
                            ->in( @INC );
 
It just cleans up the list from file paths to module declarations. It takes

/usr/local/lib/perl5/site_perl/5.8.2/Parse/RecDescent.pm

and turns it into "Parse::RecDescent". @INC is sorted longest-first because sometimes one path is actually a sub-path of the other. Both of these are in my @INC:

/usr/local/lib/perl5/site_perl
/usr/local/lib/perl5/site_perl/5.8.2

If the first one runs before the second, I'd end up with a module looking like "5.8.2::parse::RecDescent" and while technically valid, we don't really want that.

I keep seeing Barbie mentioning File::Find::Rule but I can't seem to ever bring myself to use it. Too simple to do it manually...I guess most of the time I'm doing an operation on each file, not getting a list of files, so it doesn't really save me anything.

________________________________________
Andrew - Perl Monkey
 
It was actually Barbie's constant use of it that led me to take a look. I've always hated the interface of File::Find. It's a matter of personal preference I suppose.

Code:
do_stuff($_) for (File::Find::Rule->somerule->another_rule);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top