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

I have been trying to solve this problem for a while ... I am using an old machine with limited (read cheap) hardware as a webserver serving out simple personal pages. I need perl running so that I can put some of my scripts on it etc ... however perl and its libraries are taking up a lot of space and I am trying to remove the modules that are just sitting there doing nothing ... is there any way I can find out which files/modules in the @INC directories I can remove?

Replies are listed 'Best First'.
Re: Perl modules actually in use
by busunsl (Vicar) on May 02, 2002 at 09:48 UTC
    If this is on Unix you can check the access time of the modules.

    • Use the Unix command find to find files accessed recently (-anewer):
      touch -t 200205010000 /tmp/x find /usr/lib/perl5/lib -anewer /tmp/x rm /tmp/x
    • Use Find::File and Perl's stat function:
      #!/usr/bin/perl use strict; use warnings; use File::Find; find ( sub { print $Find::File::name, "\n" if (stat($Find::File::name))[8] > time - 60*60*24*30 } )

    update: added find example
    update2: added File::Find example

Re: Perl modules actually in use
by tachyon (Chancellor) on May 02, 2002 at 10:17 UTC

    A typical perl install is "only" 20-30MB which is pretty small these days. Anyway, the core itself (/perl/bin/perl.exe) is only about 600kB so there is room for some pruning. If you have the ActiveState distribution you will have 12MB in the /perl/html/ dir that you can ditch immediately. /perl/lib/ contains the core modules (~10MB)and /site/lib/ the non core modules (~5MB) You could probably remove /perl/site/lib/ with impunity. Unfortunately many of the core modules are dependent on each other so you will need to exercise care in /perl/lib/

    You can find all the sytem related ports here if you remove too much http://www.cpan.org/ports/index.html

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Actually I fibbed when I said it was ONLY running a webserver ... I am also running dns, proxy, dhcp server but all in small footprints on an old 20MB HDD ... i am essentially using this box as a server for my home network ... the machine does not even have a reliable video card! I need space for logs and my perl scripts that I will be testing on that server. Plus I am also running apache on it as I need the mod_perl environ. for the stuff i am testing.
      Your point about the core modules dependencies are very prudent and that was my worry when I was thinking of a way to cut the perl distrib size down.
      i might be able to get away with the find example given above ... and run it hard for a few days to make sure that every path is run and then check the access times.
Re: Perl modules actually in use
by ariels (Curate) on May 02, 2002 at 11:04 UTC

    Here's a way...

    Add an END block to your codes, and print out keys %INC. The hash %INC holds pathnames for all loaded modules. That should give you a list of all the modules you must have. (Note, however, that it doesn't include shared objects (DLLs), so you can't blithely delete those on the grounds they show up nowhere...).

    If your code uses new modules in END blocks, you'll need to be more indirect. One way is to use the DESTROY method of an object which references itself (to get it destroyed only in global destruction).


    package ModuleReport; END { print "$_\n" for (sort keys %INC); } 1;
Re: Perl modules actually in use
by derby (Abbot) on May 02, 2002 at 11:56 UTC
    netjackal,

    You don't say what type of OS you're using but if you can you want to consider using busybox to help save on space.

    -derby

      I do actually know about busybox through a friend of mine and it is on my todo list. The main issue is not really about running out of space (it is a secondary one) but that there are perl modules lying around which dont do anything for me and is lying there taking up diskspace.
      I am installing debian on the box and the default perl libs installed are quite large.
      I can live with having a huge CGI.pm 'cos i dont have a choice as some of my stuff requires (or should I say use) it but there are perl libs installed there that serves no purpose right now.
      Both the compressed fs and busybox suggestions are great (and are on my todos in terms of upgrade due to time and knowledge constraints) but I want to start the perl from a minimal state.
Re: Perl modules actually in use
by mattr (Curate) on May 02, 2002 at 11:33 UTC
    You also might consider creating a compressed filesystem. I have not tried it myself but many people apparently have. Not 2.4 compatible yet. An article on it is here.