@@ -, +, @@ prefixes 'ddc' (Dewey) and whose call numbers contain prefixes, e.g., J DVD 700.1 ABC and J DVD 850 DEF. the two created in step 1. Obsere that that items are sorted in the incorrect order, with "J DVD 850 DEF" coming before "J DVD 700.1 ABC". Alternatively, run the following SQL to see the incorrect sort order: SELECT cn_sort, itemcallnumber FROM items WHERE itemcallnumber LIKE 'J DVD%' ORDER BY cn_sort; recalculated. corrected. --- C4/ClassSortRoutine/Dewey.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/C4/ClassSortRoutine/Dewey.pm +++ a/C4/ClassSortRoutine/Dewey.pm @@ -67,9 +67,13 @@ sub get_class_sort_key { $init =~ s/^([\p{IsAlpha}]+)/$1 /; my @tokens = split /\.|\s+/, $init; my $digit_group_count = 0; + my $first_digit_group_idx; for (my $i = 0; $i <= $#tokens; $i++) { if ($tokens[$i] =~ /^\d+$/) { $digit_group_count++; + if (1 == $digit_group_count) { + $first_digit_group_idx = $i; + } if (2 == $digit_group_count) { $tokens[$i] = sprintf("%-15.15s", $tokens[$i]); $tokens[$i] =~ tr/ /0/; @@ -78,7 +82,7 @@ sub get_class_sort_key { } # Pad the first digit_group if there was only one if (1 == $digit_group_count) { - $tokens[0] .= '_000000000000000' + $tokens[$first_digit_group_idx] .= '_000000000000000' } my $key = join("_", @tokens); $key =~ s/[^\p{IsAlnum}_]//g; --