File: cl2moneycsv.pl

package info (click to toggle)
chalow 1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 444 kB
  • sloc: perl: 1,534; makefile: 53
file content (98 lines) | stat: -rwxr-xr-x 2,521 bytes parent folder | download | duplicates (7)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env perl
# $Id: cl2moneycsv.pl,v 1.1 2003/07/31 14:36:20 yto Exp $
# ChangeLog Dzȷ!
#  ref. <http://nais.to/~yto/doc/zb/0016.html#kakeibo>
#
# եޥå
# * .+?ʪ:
# ^\t[][ڡ][][]$
# - ڡȾѤǤѤǤɤ
# - ۤȾѿ奫ޤƤϤʤ
#
# 
# - ܸ쥳ɤ EUC 
# - Excel ɤ߹ޤʸɤ Shift-JIS Ѵɬפ
#
# ¹
# 
# $ cat ChangeLog
# 2003-08-02  YAMASHITA Tatsuo  <yto@example.com>
# 
# 	* Ǥ: 餷Ƥ
# 
# 	* p:ʪ: 
# 	 ѡ 1050
# 	 ӥˤǻ 380
# 
# 2003-08-01  YAMASHITA Tatsuo  <yto@example.com>
# 
# 	* Ǥ: DZDz衣
# 
# 	* p:ʪ: 
# 	 եȥա 525
# 	ͷ Dz 2000
# 	  420
# 	 ѡ 780
# 
# 2003-07-31  YAMASHITA Tatsuo  <yto@example.com>
# 
# 	* Ǥ: ë˽гݤ
# 
# 	* p:ʪ: 
# 	 쥹ȥ 3000
# 	 ë 640
# 	 ڥȥĢ 550
# 
# $ cl2moneycsv.pl ChangeLog
#           ,  ,  ,  ,  ͷ,  ,  ,  ,  ,  ¾
# 2003.07.31,3000,   0, 640,   0,   0,   0, 550,   0,   0
# 2003.08.01, 525, 780, 420,2000,   0,   0,   0,   0,   0
# 2003.08.02,   0,1050,   0,   0, 380,   0,   0,   0,   0
# $ cl2moneycsv.pl -m ChangeLog  (˽)
#           ,  ,  ,  ,  ͷ,  ,  ,  ,  ,  ¾
# 2003-07,3000,   0, 640,   0,   0,   0, 550,   0,   0
# 2003-08, 525,1830, 420,2000, 380,   0,   0,   0,   0
# $ cl2moneycsv.pl -m ChangeLog | nkf -s > kaimono.csv

use strict;

### ޥɥ饤
use Getopt::Long;
Getopt::Long::Configure('bundling');
my ($mon_mode);
GetOptions('m|monthly' => \$mon_mode);

#  an item of expendidure
my @lioe = ('', '', '', 'ͷ', '', '', '', '', '¾');

my $date;	
my $inside_flag = 0;

my %entry = ();
while (<>) {
    if (/^((\d{4}-\d\d)-\d\d)/) { # դ򥭡
	if (defined $mon_mode) {
	    $date = $2;		# = year-month
	} else {
	    $date = $1;		# = year-month-day
	    $date =~ s|-|.|g;	# for Excel
	}
	next;
    } elsif (/ʪ:/) {	# ȷǡҥ֥åλϤޤ
	$inside_flag = 1;
    } elsif ($inside_flag == 1) { # ֥å
	if (/^\s*$/ and $inside_flag == 1) { # ֥åν
	    $inside_flag = 0;
	} elsif (/^\t(.+?)(\s|\xa1\xa1).*(\s|\xa1\xa1)(\d+)$/) {
	    $entry{$date}->{$1} += $4;
	}
    }
}


print " " x 10, ",  ", join(',  ', @lioe), "\n";

foreach my $date (sort keys %entry) {
    print "$date,";
    print join(',', map {sprintf "%4d", $entry{$date}{$_}} @lioe), "\n";
}