in reply to Remove an Installed Module

Since this is very useful information. I would like to add that:

ExtUtils::Packlist

Has a script that is better then the above. If you want to limit it to a single module you can simply add:
next if ($module ne $ARGV[0]);
After the the grep line.

One Planet, One Internet... We Are All Connected...

Replies are listed 'Best First'.
Re^2: Remove an Installed Module
by Anonymous Monk on Jan 27, 2011 at 12:57 UTC
    Where what?
      Original Example:
      #!/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"); 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); } } } }
      And you can simply add:
      next if ($module ne $ARGV[0]);
      after the grep line and you will effectively make this script the equivalent of rm for perl.
      I actually have it named rmpmod on all of my machines.
      For example:
      $ rmpmod DBD::Pg
      Removes the DBD::Pg module from the machine.
      One Planet, One Internet...
      We Are All Connected...