diff options
author | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-04-28 14:23:27 +0100 |
---|---|---|
committer | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-04-28 14:23:27 +0100 |
commit | c005c07d2b99707fb87b11b27476635015d6d941 (patch) | |
tree | 6294f10e583374ad8c89de38f4588d6ac5416915 /ledgerscripts/apply_categories.pl | |
parent | ef297ce2c65aead25b755f9cc3ed4b8705733299 (diff) |
working through ledger scripts
Diffstat (limited to 'ledgerscripts/apply_categories.pl')
-rw-r--r-- | ledgerscripts/apply_categories.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ledgerscripts/apply_categories.pl b/ledgerscripts/apply_categories.pl new file mode 100644 index 0000000..94bb913 --- /dev/null +++ b/ledgerscripts/apply_categories.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use warnings; +use strict; + + +open (my $cat_file, "<", "expense_categories") or die + "Can't open expense_categories file"; + +my %categories; + +while (local $_ = <$cat_file>) { + if (/(.*)@(.*)/) { + $categories{$1} = $2; + } +} +close $cat_file; + +local $/ = ""; # switch to paragraph mode + +while (my $block = <>) { + if ($block =~ m/\d{4}.*\* (.*)\n.*(Expenses:.*)£/s) { + while (my ($k, $v) = each %categories) { + if ($k eq $1) { + $block =~ s/$2/Expenses:$v/; + }; + } + print $block; + }; +} |