#!/usr/bin/perl -w use strict; my $month = shift @ARGV || 6; my $day = shift @ARGV || 30; my @types = ('once', 'monthly', 'daily'); my @mconst = (1, $month, $day); print "Assuming $month months time, $day days per month:\n"; # find all entries my %file; for (@types) { chomp(@{$file{$_}} = `find $_ -type f 2>/dev/null`); } # read in and display each entry my %sum; for my $type (@types) { print "\u$type:\n"; @{$sum{$type}}{'n','p','b'}=(0,0,0); for my $name (@{$file{$type}}) { chomp(my $amt = `cat $name`); (my $pname = $name) =~ s/$type\///; print "\t\u$pname : $amt\n"; $sum{$type}{'b'} += $amt; $sum{$type}{'p'} += $amt if $amt > 0; $sum{$type}{'n'} += $amt if $amt < 0; } } # calculate various sums for my $x (0..$#mconst) { for my $y ($x..$#types) { for (keys %{$sum{$types[$y]}}) { $sum{$types[$y]}{$_} *= $mconst[$x] }; } } # print the sums found for my $type (@types) { print "\u$type : $sum{$type}{'b'} ($sum{$type}{'p'} $sum{$type}{'n'})\n"; } #print all the grand totals my $grandsum; for (@types) { $grandsum += $sum{$_}{'b'}; } for my $title ("Grand", "Per month", "Per Day") { $grandsum /= shift @mconst; print "$title: $grandsum\n"; }