Parallel hashes made no sense here.

Since the main index is size, no reason not to have a single hash that
is so-keyed, and have subhash with two keys for checklist and labels.
This commit is contained in:
Bradley M. Kuhn 2016-01-07 12:42:51 -08:00
parent dd8d8cba37
commit 97e772b89c

View file

@ -63,8 +63,7 @@ my $sp = new Supporters($dbh, [ "none" ]);
my(@supporterIds) = $sp->findDonor({}); my(@supporterIds) = $sp->findDonor({});
my $overallCount = 0; my $overallCount = 0;
my %labelsLines; my %lines;
my %boxLines;
foreach my $id (@supporterIds) { foreach my $id (@supporterIds) {
my $sizeNeeded; my $sizeNeeded;
@ -89,30 +88,29 @@ foreach my $id (@supporterIds) {
next; next;
} }
$overallCount++; $overallCount++;
$labelsLines{$sizeNeeded} = "" unless defined $labelsLines{$sizeNeeded}; $lines{$sizeNeeded}{labels} = "" unless defined $lines{$sizeNeeded}{labels};
$boxLines{$sizeNeeded} = [] unless defined $boxLines{$sizeNeeded}; $lines{$sizeNeeded}{checklist} = [] unless defined $lines{$sizeNeeded}{checklist};
$labelsLines{$sizeNeeded} .= '\mlabel{}{TO: \\\\ ' . join(' \\\\ ', split('\n', $latexPostal)) . "}\n"; $lines{$sizeNeeded}{labels} .= '\mlabel{}{TO: \\\\ ' . join(' \\\\ ', split('\n', $latexPostal)) . "}\n";
my $shortLatexPostal = latex_encode(sprintf('%-30.30s', join(" ", reverse split('\n', $postalAddresses[0])))); my $shortLatexPostal = latex_encode(sprintf('%-30.30s', join(" ", reverse split('\n', $postalAddresses[0]))));
push(@{$boxLines{$sizeNeeded}}, '{ $\Box$} &' . sprintf("%-3d & %5s & %-30s & %s ", push(@{$lines{$sizeNeeded}{checklst}}, '{ $\Box$} &' . sprintf("%-3d & %5s & %-30s & %s ",
$id, encode('UTF-8', $sp->getLedgerEntityId($id)), $id, encode('UTF-8', $sp->getLedgerEntityId($id)),
encode('UTF-8', $sizeNeeded), encode('UTF-8', $sizeNeeded),
$shortLatexPostal) . $shortLatexPostal) .
'\\\\ \hline' . "\n"); '\\\\ \hline' . "\n");
} }
my $lineCount = 0; my $lineCount = 0;
foreach my $size (sort { $a cmp $b } keys %boxLines) { foreach my $size (sort { $a cmp $b } keys %lines) {
foreach my $line (@{$boxLines{$size}}) { foreach my $line (@{$lines{$size}{boxes}}) {
if ($lineCount++ > 40) { if ($lineCount++ > 40) {
$lineCount = 0; $lineCount = 0;
print LIST "\n\n", '\end{tabular}',"\n\\pagebreak\n\\begin{tabular}{|l|l|l|l|l|} \\hline\n"; print LIST "\n\n", '\end{tabular}',"\n\\pagebreak\n\\begin{tabular}{|l|l|l|l|l|} \\hline\n";
} }
print LIST $line; print LIST $line;
} }
print LABELS $labelsLines{$size}; print LABELS $lines{$size}{labels};
delete $labelsLines{$size}; delete $lines{$size}{labels};
} }
die "error: parallel hashes had different keys?" unless scalar(keys %labelsLines) <= 0; die "error: parallel hashes had different keys?" unless scalar(keys %{$lines{$size}{labels}}) <= 0;
print LIST "\n\n", '\end{tabular}',"\n"; print LIST "\n\n", '\end{tabular}',"\n";
print LIST "FINAL INVENTORY EXPECTED\n\\begin{tabular}{|l|l|} \\hline\n"; print LIST "FINAL INVENTORY EXPECTED\n\\begin{tabular}{|l|l|} \\hline\n";