Revision 31796, 0.7 KB
(checked in by kjdon, 3 years ago)

adding the collections' frameworks

Line  

1  ## CatalogNumList.pm A version of List that correctly sorts Taonga catalogue numbers 

2  package CatalogNumList; 

3  

4  use List; 

5  

6  use strict; 

7  

8  sub BEGIN { 

9  @CatalogNumList::ISA = ('List'); 

10  } 

11  

12  # all I want to do with this classifier is sort numbers like 3q1 and 

13  # 3q1/2a so that the numeric parts are sorted numerically. 

14  sub alpha_numeric_cmp 

15  { 

16  my ($self,$a,$b) = @_; 

17  my ($a1, $a2, $a3) = $a =~ m@^3q(\d+)(?:/(\d+)(.*))?$@; 

18  my ($b1, $b2, $b3) = $b =~ m@^3q(\d+)(?:/(\d+)(.*))?$@; 

19  

20  if ($a1 && $b1) { 

21  if ($a1 != $b1) { 

22  return ($a1 <=> $b1); 

23  } 

24  if ($a2 && $b2) { 

25  if ($a2 != $b2) { 

26  return ($a2 <=> $b2); 

27  } 

28  return ($a3 cmp $b3); 

29  } 

30  } 

31  return $a cmp $b; 

32  } 

33  

34  

35  

36  1; 
