version 1.13, 2020/11/18 21:32:16 |
version 1.14, 2020/11/18 22:25:05 |
|
|
|
|
# === MAIN PROGRAM ===================================================== |
# === MAIN PROGRAM ===================================================== |
|
|
my ($csv_account, $fn, $in, $account_name, $delim, @compiled); |
|
|
|
# Parse command line arguments. |
|
getopts 'I:' or usage; |
getopts 'I:' or usage; |
if ($opt_I) { |
unless ($opt_I) { |
$account_name = $opt_I; |
warn "The option -I is required."; |
$banks{$account_name} or die "unknown accountname: $account_name"; |
|
$fn = "import_" . $account_name . ".txt"; |
|
open $in, $fn or die "$fn: $!"; |
|
} else { |
|
usage; |
usage; |
} |
} |
|
my $account_name = $opt_I; |
|
$banks{$account_name} or die "unknown accountname: $account_name"; |
|
|
# Parse the configuration file. |
# Parse the configuration file. |
|
my $fn = "import_" . $account_name . ".txt"; |
|
open my $in, '<', $fn or die "$fn: $!"; |
|
my ($csv_account, $delim, $header, @compiled); |
while (<$in>) { |
while (<$in>) { |
chomp; |
chomp; |
next if /^(?:#|$)/; |
next if /^(?:#|$)/; |
|
|
$delim = $1; |
$delim = $1; |
next; |
next; |
} |
} |
|
if (/^HEADER\s+(.*)$/) { |
|
$header and die "duplicate HEADER line: $1"; |
|
$header = $1; |
|
next; |
|
} |
$delim or die "no DELIM line in $fn"; |
$delim or die "no DELIM line in $fn"; |
s/^(.*)$delim\s+(\d+)\s+(\S+)// or |
s/^(.*)$delim\s+(\d+)\s+(\S+)// or |
die "$fn import parse error: $line"; |
die "$fn import parse error: $line"; |
|
|
$csv_account or die "no ACCOUNT line in $fn"; |
$csv_account or die "no ACCOUNT line in $fn"; |
|
|
# Parse the CSV file from the bank. |
# Parse the CSV file from the bank. |
chomp(my $header = <>); |
|
while (<>) { |
while (<>) { |
chomp; |
chomp; |
next if (/^$/); |
next if (/^$/); |
my $line = $_; |
my $line = $_; |
|
if ($header) { |
|
$line eq $header |
|
or die "expected HEADER $header\nbut got $line"; |
|
undef $header; |
|
next; |
|
} |
my @fields = split /$delim/, $line; |
my @fields = split /$delim/, $line; |
my $matches = 0; |
my $matches = 0; |
my ($account, $booking); |
my ($account, $booking); |