[greenstone-devel] bug in AZList.pm

From Don Gourley
DateWed, 15 Oct 2003 08:45:07 -0400 (EDT)
Subject [greenstone-devel] bug in AZList.pm
I've found what I think is a bug in AZList.pm. It seems that
if the last un-compacted subsection of a list is a letter
(not 0-9) and has more than 30 entries in it (ie. > $max),
then the compactlist() subroutine will add an empty list of
OIDs to it using the $currentlastletter from the previous
compacted section. This results in an incorrect last label
in the HList as described in a discussion on greenstone-users
under the subject "Title list W-P?".

My fix for this was to put the epilogue code in compactlist()
inside a conditional such that it is not executed if the
list of OIDs leftover from the previous loop through
%$classhashref is empty. We discovered the bug and tested the
fix in 2.37, but the AZList.pm in 2.40a has the same code:

# add final OIDs to last sub-classification if there aren't many otherwise
# add final sub-classification
# BUG FIX: don't add anything if there are no currentOIDs
if (@currentOIDs) {
if (scalar (@currentOIDs) < $min) {
my ($newkey) = $lastkey =~ /^(.)/;
@currentOIDs = (@{$compactedhash->{$lastkey}}, @currentOIDs);
delete $compactedhash->{$lastkey};
@{$compactedhash->{"$newkey-$currentlastletter"}} = @currentOIDs;
} else {
if ($currentfirstletter eq $currentlastletter) {
@{$compactedhash->{$currentfirstletter}} = @currentOIDs;
} else {
@{$compactedhash->{"$currentfirstletter-$currentlastletter"}} =

return $compactedhash;

Many thanks to Stephen DeGabrielle for showing me how to debug

-Don Gourley