-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_monthly
executable file
·53 lines (41 loc) · 1018 Bytes
/
stats_monthly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
use POSIX qw(strftime);
open IN, "<ambar.txt";
while(<IN>)
{
$i++;
#skip whitespace lines
s/\#.*//;
if (/^\s*$/) {next}
if (/^DEFAULT_CURRENCY/) {next}
#if (/^(\S+)\s+\S+\s+(\S+)/)
if (/^(\S+)\s+\S+\s+([\d\$\.]+)($|\s)/)
{
$sum=$2;
$date=$1;
$month=$date;
$month=~s@-\d\d$@@;
if ($sum=~/\$$/)
{
$sum=~s/\$//;
}
else
{
$sum=ccc($sum,"byr","usd",$date);
}
$month_hash{$month}+=$sum ;
}
else
{print "junk line #$i : $_ \n exit!\n"; exit; }
}
# print current month payments
foreach $date (sort keys %month_hash) { print $date," ",sprintf("%.2f\$", $month_hash{$date}),"\n"; }
sub ccc {
my $amount=shift;
my $from=shift;
my $to=shift;
my $date=shift;
my $ccc=`ccc $amount $from $to $date`;
chomp $ccc;
return $ccc;
}