#!/usr/bin/perl -w

# Lists distinct languages named in subjects.

use warnings 'FATAL', 'all';
# Make every warning fatal.

use strict;
# Require strict checking of variable references, etc.

use utf8;
# Make Perl interpret the script and standard files as UTF-8 rather than bytes.

open IN, '<:utf8', 'sublangs.txt';
# Open the input file for reading.

open OUT, '>:utf8', 'ulangs.txt';
# Create or truncate an output file and open it for writing.

my ($i, @seg, %ulang);

while (<IN>) {
# For each subject line:

	chomp;
	# Delete its trailing newline.

	@seg = (split /\t/);
	# Identify a list of its segments.

	foreach $i (1, 2) {
	# For each language column:

		unless (($seg[$i] eq '') || ($seg[$i] eq '-') || (exists $ulang{$seg[$i]})) {
		# If it isn’t blank and isn’t yet in the table of language names:

			$ulang{$seg[$i]} = '';
			# Add it to the table of language names.

		}

	}

}

foreach $i (sort (keys %ulang)) {
# For each language specification in the table:

	$i =~ /^<([a-z])>(.+)$/;
	# Identify its type and name.

	print OUT "$1\t$2\n";
	# Output them.

}

close IN;
# Close the input file.

close OUT;
# Close the output file.
