Changeset 6806


Ignore:
Timestamp:
2004-02-16T17:22:58+13:00 (20 years ago)
Author:
jrm21
Message:

Bah. We were accidentally dropping the last classification because of a typo
(we were checking if @currentOIDS, when it should be currentOIDs).
Now we have "use strict;" to tell us when we use an undeclared variable!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/classify/AZList.pm

    r6761 r6806  
    3535    @ISA = ('BasClas');
    3636}
     37
     38use strict;
    3739
    3840my $arguments =
     
    230232    # don't need to do any splitting if there are less than 39 (max + min -1) classifications
    231233    if ((scalar @$classlistref) <= 39) {
    232     foreach $subOID (@$classlistref) {
     234    foreach my $subOID (@$classlistref) {
    233235        push (@{$classifyinfo->{'contains'}}, {'OID'=>$subOID});
    234236    }
     
    237239   
    238240    # first split up the list into separate A-Z and 0-9 classifications
    239     foreach $classification (@$classlistref) {
     241    foreach my $classification (@$classlistref) {
    240242    my $title = $self->{'list'}->{$classification};
    241243
     
    255257
    256258    my @tmparr = ();
    257     foreach $subsection (sort keys (%$classhash)) {
     259    foreach my $subsection (sort keys (%$classhash)) {
    258260    push (@tmparr, $subsection);
    259261    }
     
    266268    }
    267269
    268     foreach $subclass (@tmparr) {
     270    foreach my $subclass (@tmparr) {
    269271    my $tempclassify = $self->get_entry($subclass, "VList");
    270     foreach $subsubOID (@{$classhash->{$subclass}}) {
     272    foreach my $subsubOID (@{$classhash->{$subclass}}) {
    271273        push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
    272274    }
     
    282284    my $compactedhash = {};
    283285    my @currentOIDs = ();
    284     my $currentfirstletter = "";
    285     my $currentlastletter = "";
    286     my $lastkey = "";
     286    my $currentfirstletter = "";  # start of working bin
     287    my $currentlastletter = "";   # end of working bin
     288    my $lastkey = "";             # the name of the last completed key
    287289
    288290    # minimum and maximum documents to be displayed per page.
     
    294296    my $max = 30;
    295297
    296     foreach $subsection (sort keys %$classhashref) {
     298    foreach my $subsection (sort keys %$classhashref) {
    297299    if ($subsection eq '0-9') {
     300        # leave this bin as-is... copy it straight across
    298301        @{$compactedhash->{$subsection}} = @{$classhashref->{$subsection}};
    299302        next;
     
    302305    if ((scalar (@currentOIDs) < $min) ||
    303306        ((scalar (@currentOIDs) + scalar (@{$classhashref->{$subsection}})) <= $max)) {
     307        # add this letter to the bin and continue
    304308        push (@currentOIDs, @{$classhashref->{$subsection}});
    305309        $currentlastletter = $subsection;
    306310    } else {
    307 
     311        # too many or too few for a separate bin
    308312        if ($currentfirstletter eq $currentlastletter) {
    309313        @{$compactedhash->{$currentfirstletter}} = @currentOIDs;
     
    314318        }
    315319        if (scalar (@{$classhashref->{$subsection}}) >= $max) {
     320        # this key is now complete. Start a new one
    316321        $compactedhash->{$subsection} = $classhashref->{$subsection};
    317322        @currentOIDs = ();
     
    329334    # add final sub-classification
    330335    # BUG FIX: don't add anything if there are no currentOIDs (thanks to Don Gourley)
    331     if (@currentOIDS) {
    332     if (scalar (@currentOIDs) < $min) {
    333         my ($newkey) = $lastkey =~ /^(.)/;
    334         @currentOIDs = (@{$compactedhash->{$lastkey}}, @currentOIDs);
    335         delete $compactedhash->{$lastkey};
    336         @{$compactedhash->{"$newkey-$currentlastletter"}} = @currentOIDs;   
     336    if (! scalar(@currentOIDs)) {return $compactedhash;}
     337
     338    if (scalar (@currentOIDs) < $min) {
     339    my ($newkey) = $lastkey =~ /^(.)/;
     340    @currentOIDs = (@{$compactedhash->{$lastkey}}, @currentOIDs);
     341    delete $compactedhash->{$lastkey};
     342    @{$compactedhash->{"$newkey-$currentlastletter"}} = @currentOIDs;
     343    } else {
     344    if ($currentfirstletter eq $currentlastletter) {
     345        @{$compactedhash->{$currentfirstletter}} = @currentOIDs;
    337346    }
    338347    else {
    339         if ($currentfirstletter eq $currentlastletter) {
    340         @{$compactedhash->{$currentfirstletter}} = @currentOIDs;
    341         }
    342         else {
    343         @{$compactedhash->{"$currentfirstletter-$currentlastletter"}} = @currentOIDs;
    344         }
     348        @{$compactedhash->{"$currentfirstletter-$currentlastletter"}} =
     349        @currentOIDs;
    345350    }
    346351    }
Note: See TracChangeset for help on using the changeset viewer.