#!/usr/local/bin/perl # # slavonic-sort # Author: Justin Zamora # # This program sorts a transliterated Church Slavonic text according # to the ordering of the letters of the Church Slavonic alphabet. # It uses the transliteration used on the "Help Me Learn Church Slavonic" # web site, http://justin.zamora.com/slavonic # # This program is designed for sorting a vocabulary list. It assumes # that a dash surrounded by spaces separates a transliterated word # from its definition. If there is no dash on the line, it will treat # the entire line as transliterated text. if (@ARGV && $#ARGV != 0) { die "Usage: $0 file\n"; } while (<>) { $line = $_; # Separate the word from the definition ($word, $def, @rest) = split(/ - /, $line); if (@rest) { print "Entry for $word has extra dash\n"; exit 1; } if (!$def) { chomp($word); } # Remove diacritics $word =~ s/[\/\^\\\`]//go; # Generate and prepend sortable collating sequence $word =~ s/^ja/R/go; $word =~ s/ksja$/3=T/go; $word =~ s/psja$/9=T/go; $word =~ s/shch/H/go; $word =~ s/^wt/B/go; $word =~ s/zh/*/go; $word =~ s/ch/D/go; $word =~ s/sh/G/go; # Handle i before another i do { $count = $word =~ s/ii/Ii/o; } while ($count > 0); # Handle i before a vowel $word =~ s/ia/2#/go; $word =~ s/i[eE]/2)/go; $word =~ s/iI/22/go; $word =~ s/i[oO]/27/go; $word =~ s/iy/2L/go; $word =~ s/iw/28/go; $word =~ s/iu/2?/go; $word =~ s/ije/2N/go; $word =~ s/iju/2Q/go; $word =~ s/ija/2T/go; $word =~ s/ij/21/go; $word =~ s/je/N/go; $word =~ s/ju/Q/go; $word =~ s/ja/T/go; $word =~ s/ks/U/go; $word =~ s/ps/W/go; $word =~ s/i/0/go; $word =~ tr|abvgdeEZzjIkKlmnoOwpPrsStufxc"y'FV|#$%&())+/123345677899<==>?@ACJLMXY|; push @words, ($word . " | " . $line); } @sorted = sort @words; for $line (@sorted) { $line =~ s/^.*\| //; print $line; }