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"; }

In reply to Quick Finances by gryng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.