diff options
author | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-04-27 14:51:39 +0100 |
---|---|---|
committer | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-04-27 14:51:39 +0100 |
commit | 0ad0bf99f78a055b971806d2f87c7db22fa5d88e (patch) | |
tree | 835cee058e34fb7b7cfbf7c5e58d6f9bf8ba46bb /ledgerscripts/books.pl | |
parent | b7399230ebc82a1e1d72224ba82711ded3a0301e (diff) |
script works for now
Diffstat (limited to 'ledgerscripts/books.pl')
-rwxr-xr-x | ledgerscripts/books.pl | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/ledgerscripts/books.pl b/ledgerscripts/books.pl index ecb2e82..16b9d20 100755 --- a/ledgerscripts/books.pl +++ b/ledgerscripts/books.pl @@ -1,4 +1,14 @@ #!/usr/bin/env perl +# This script will check ledger budger file and look for any transactions +# with either SEJLB or HWLB in the line. These must be manually added and +# indicate a transaction involving one of the children buying a book. The +# script will reprint that block, adding an additional line that calculates +# half the cost of the time and subtracts it from their virtual account - +# we pay half, they pay half. +# +# Outputs to STDOUT so you will have to redirect it somwhere. +# +# DO NOT REDIRECT BACK TO THE FILE ITSELF use strict; use warnings; @@ -7,27 +17,24 @@ use warnings; # basically sets empty lines as a terminator when set like this local $/ = ""; -open (my $outfile, ">", "/tmp/toss.txt") - or die "Can't open output file."; - my @infile = <>; -my $child_asset_line = "(Assets:Child:CHILD)\t\t£COST\n"; +my $child_asset_line = + "(Assets:Child:CHILD)\t\t-£COST\n Assets:Current:HSBC\t\t\t£ORIGINAL\n"; for my $block (@infile) { my $child; - if ($block =~ /(SEJLB|HWLB).*Books.*(\d+\.\d+)/s) { + if ($block =~ /(SEJLB|HWLB)/ms) { if ($1 eq "HWLB") { $child = "Harvey"} else { $child = "Sophie" }; (my $cost) = ($block =~ /£(\d+\.\d+)/); (my $cat) = ($block =~ /(\w+\:\w+)/); chomp $block; - print $outfile $block; + $block =~ s/( SEJLB| HWLB)//g; + print $block; $child_asset_line =~ s/CHILD/$child/; my $halve = sprintf("%.2f", ($cost / 2)); $child_asset_line =~ s/COST/$halve/; - print $outfile "\n". " " . $child_asset_line . "\n"; - } else { print $outfile $block; } + $child_asset_line =~ s/ORIGINAL/$cost/; + print "\n". " " . $child_asset_line . "\n"; + } else { print $block; } } - -close $outfile; - |