Commit a175096b83d9b3008dc5b2a06b16c310b92b63b4
Fix merge-ledger somewhat
Charles Lehner committed on 11/1/2015, 2:07:02 AMParent: 1d0bfddc48640e483c022b27568c41a6015e9321
Files changed
merge-ledger | changed |
merge-ledger | ||
---|---|---|
@@ -92,9 +92,8 @@ | ||
92 | 92 | sub print_entry { |
93 | 93 | my ($stream, $entry) = @_; |
94 | 94 | #$stream //= \*STDOUT; |
95 | 95 | #print $stream "fh: ".($entry->{fh} // 'null').". i: ".$entry->{buffer_i}."\n"; |
96 | - print "amounts: "; | |
97 | 96 | print $_ . ", " for keys($entry->{amounts}); |
98 | 97 | print "\n"; |
99 | 98 | print $stream $_ for @{ $entry->{lines} }; |
100 | 99 | } |
@@ -102,10 +101,10 @@ | ||
102 | 101 | sub get_oldest_entry { |
103 | 102 | return unless scalar @buffer; |
104 | 103 | |
105 | 104 | # pick the oldest entry |
106 | - my $oldest = shift @buffer; | |
107 | - for my $entry (@buffer) { | |
105 | + my $oldest = $buffer[0]; | |
106 | + for my $entry (@buffer[1..$#buffer]) { | |
108 | 107 | if ($entry->{date} < $oldest->{date}) { |
109 | 108 | $oldest = $entry; |
110 | 109 | } |
111 | 110 | } |
@@ -115,10 +114,10 @@ | ||
115 | 114 | |
116 | 115 | sub entry_matches_date { |
117 | 116 | my ($entry, $date) = @_; |
118 | 117 | my $diff = $date - $entry->{date}; |
119 | - printf("%s, %s: %s days\n", $date, $entry->{date}, $diff); | |
120 | - return (abs(int($diff->days)) < $time_difference); | |
118 | + printf("%s, %s: %s days\n", $date, $entry->{date}, $diff->days); | |
119 | + return (abs($diff) < $time_difference); | |
121 | 120 | } |
122 | 121 | |
123 | 122 | sub entry_matches_amounts { |
124 | 123 | my ($entry, $amounts) = @_; |
@@ -138,9 +137,9 @@ | ||
138 | 137 | my $fh = $entry->{fh}; |
139 | 138 | my @matches = grep { |
140 | 139 | defined $_ and |
141 | 140 | $fh != $_->{fh} and |
142 | - #entry_matches_date($_, $date) and | |
141 | + entry_matches_date($_, $date) and | |
143 | 142 | entry_matches_amounts($_, $amounts) |
144 | 143 | } @buffer; |
145 | 144 | # append original entry |
146 | 145 | unshift @matches, $entry if (scalar @matches); |
@@ -241,8 +240,9 @@ | ||
241 | 240 | replace_entry($entry); |
242 | 241 | } |
243 | 242 | } else { |
244 | 243 | # No matching entries. |
245 | - # Print the entry | |
244 | + # Print the entry and pick a new one | |
246 | 245 | print_entry \*OUTFILE, $entry; |
246 | + replace_entry($entry); | |
247 | 247 | } |
248 | 248 | } |
Built with git-ssb-web