Changeset 22667

Show
Ignore:
Timestamp:
18.08.2010 13:19:55 (10 years ago)
Author:
mdewsnip
Message:

Added code to prevent uninitialized value errors when trying to sort on metadata fields that don't exist in the collection.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/classify/List.pm

    r22175 r22667  
    867867    # Force a stable sort (Perl 5.6's sort isn't stable) 
    868868    # !! The [0] bits aren't ideal (multiple metadata values) !!  
    869     @OIDs = @OIDs[ sort { $OID_to_metadata_values_hash_ref->{$OIDs[$a]}[0] cmp $OID_to_metadata_values_hash_ref->{$OIDs[$b]}[0] || $a <=> $b; } 0..$#OIDs ]; 
     869    @OIDs = @OIDs[ sort { 
     870      if (defined($OID_to_metadata_values_hash_ref->{$OIDs[$a]} && defined($OID_to_metadata_values_hash_ref->{$OIDs[$b]}))) 
     871      { 
     872        $OID_to_metadata_values_hash_ref->{$OIDs[$a]}[0] cmp $OID_to_metadata_values_hash_ref->{$OIDs[$b]}[0]; 
     873      } 
     874      else 
     875      { 
     876        $a <=> $b; 
     877      } 
     878    } 0..$#OIDs ]; 
    870879    } 
    871880    return @OIDs;