Function in Perl similar to phpinfo() from PHP

MagnuM

Verified User
Joined
Oct 24, 2003
Messages
102
Location
Romania
Hello, I don't have experience in Perl language, but I want to know some information, like Perl version or Perl installed modules on my server. I supose it need to be something like the phpinfo() function available in PHP.
Can you give me any hints?
 
The following script will list Perl modules installed on your server:

Code:
#!/usr/local/bin/perl -w
    use strict;
    use IO::Dir;
    use ExtUtils::Packlist;
    use ExtUtils::Installed;
    sub emptydir($) {
        my ($dir) = @_;
        my $dh = IO::Dir->new($dir) || return(0);
        my @count = $dh->read();
        $dh->close();
        return(@count == 2 ? 1 : 0);
    }
    # Find all the installed packages
    print("Finding all installed modules...\n");
    my $installed = ExtUtils::Installed->new();
    foreach my $module (grep(!/^Perl$/, $installed->modules())) {
       my $version = $installed->version($module) || "???";
       print("Found module $module Version $version\n");
       [b]next;[/b]
       print("Do you want to delete $module? [n] ");
       my $r = <STDIN>; chomp($r);
       if ($r && $r =~ /^y/i) {
          # Remove all the files
          foreach my $file (sort($installed->files($module))) {
             print("rm $file\n");
             unlink($file);
          }
          my $pf = $installed->packlist($module)->packlist_file();
          print("rm $pf\n");
          unlink($pf);
          foreach my $dir (sort($installed->directory_tree($module))) {
             if (emptydir($dir)) {
                print("rmdir $dir\n");
                rmdir($dir);
             }
          }
       }
    }

If you comment out "next" command, it will also allow you to remove modules.
 
Thanks, Webcart.

Very nice.

Note that we had to, and some other admins may have to, change the path to the perl interpreter in the first line.

We changed it as follows:

!/usr/bin/perl -w

Is it your script?

Is it copyright? Covered under any license?

I'm thinking about modifying it to show output in html, and also removing the code that allows you to delete modules, and make it web accessible.

Can you see any problem with that?

Jeff
 
The script is taken from http://www.perldoc.com/ , so I don't think there are any license issues.


As far as I recall, I didn't do any code modifications beside adding "NEXT" line which converted module removal script into a script that can only list installed modules.

In any case, I wouldn't mind :)
 
Back
Top