diff options
Diffstat (limited to '')
-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; + }; +} |