#!/usr/bin/perl

# sudo dpkg -l | awk '{print $2}' | grep -vE '^(Status|Err|Name|^$)' > /tmp/pkg.list

my $file = '/tmp/pkg.list' ;

open (FH, $file) ;
while (<FH>) {
chomp ($_) ;
my $pkg = $_ ;

next if ($pkg =~ /l10n/) ;

my $optified = 0 ;
my @filelist = `dpkg -L $pkg` ;
foreach my $file (@filelist) {
chomp $file ;
$optified = 1 and last if ($file =~ /^\/opt/) ;
}
if ($optified == 0) {
my @duFileList ;
foreach my $file (@filelist) {
next if ($file =~ /^\/home/) ;
push @duFileList, $file if ($file =~ /.+\/.+\..+$/) ;
}
my @out = `du -ch @duFileList 2>stderr` ;
foreach my $duOut (@out) {
next if ($duOut !~ /total/) ;
chomp $duOut ;
print "$duOut \t $pkg\n" ;
}
}
}
close (FH) ; 
