#!/usr/bin/perl -w use strict; $|++; use Config; use IPC::Open2; use Memoize; memoize('lines_in_file'); use File::Basename; ## CONFIG my $PAT = "/home/merlyn/Html/merlyn/WebTechniques/col??.listing.txt"; ## END CONFIG my $perlpath = $Config{perlpath}; my $privlib = $Config{privlib}; my $sitelib = $Config{sitelib}; my $files_regex = qr/^(\Q$privlib\E|\Q$sitelib\E)/; @ARGV = glob $PAT or die "no files?"; undef $/; my $source_grand = 0; my $used_grand = 0; while (<>) { for (split /^\#\#\#.*listing.*\n/im) { next if /Apach[e]::/; # bleh next unless my $source_count = tr/\n//; open2(\*RDR, \*WTR, "$perlpath -cTMDevel::Modlist=path 2>&1") or die "Cannot create pipe or fork or something: $!"; print WTR $_; close WTR; $_ = ; close RDR; my $used_count = 0; for (split /\n/) { next unless /$files_regex/; $used_count += lines_in_file($_); } printf "%30s %6d %6d\n", basename($ARGV), $source_count, $used_count; $source_grand += $source_count; $used_grand += $used_count; } } printf "%30s %6d %6d\n", "grand total =>", $source_grand, $used_grand; sub lines_in_file { my $filename = shift; my $handle = \do { local *STDIN }; open $handle, "<$filename" or return 0; read $handle, my $buffer, -s $handle; $buffer =~ tr/\n//; }