This program was thrown together to see whether I was going to go bankrupt before the end of the year (I don't get any income again until then).

The code abstracts itself a little, to make it somewhat a learning experience (which is why I'm posting it), but the abstraction doesn't really help the readability. I guess, you can say it's more extendable, whatever :) .

Anyway, you put the code in a file in a sub-directory. Then for each entry in your finance you type:

echo amount > frequency/name

Where amount is a positive or negative number, frequency is either "once", "monthly", or "daily". Name is whatever you want. Make sure you make the corresponding directories "once", "monthly", and "daily" before trying to put a file in there.

Run the program and you'll get a summary. Yeah I know, you're not supposed to use a filesystem as a database. I didn't feel like editing a text file, I like 'find . -not -name "*.pl" -type f|xargs grep ""' to see what I've entered instead ;) .

Enjoy,
Gryn

#!/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"; }