From c005c07d2b99707fb87b11b27476635015d6d941 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 28 Apr 2022 14:23:27 +0100 Subject: working through ledger scripts --- ledgerscripts/apply_categories.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ledgerscripts/apply_categories.pl (limited to 'ledgerscripts/apply_categories.pl') 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; + }; +} -- cgit v1.2.3