Abbreviations, automatic: Difference between revisions

Content added Content deleted
(Added Go)
(Added Perl example)
Line 834: Line 834:
2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
</pre>
</pre>

=={{header|Perl}}==
Output is the same as for Perl 6.
{{trans|Perl 6}}
<lang perl>use utf8;
binmode STDOUT, ":utf8";

sub auto_abbreviate {
my($string) = @_;
my @words = split ' ', $string;
return '' unless @words;
map { $max = length($_) if length($_) > $max } @words;
for $i (1..$max-1) {
my %seen;
return $i if @words == grep {!$seen{substr($_,0,$i)}++} @words;
}
return '∞';
}

open $fh, '<:encoding(UTF-8)', 'DoWAKA.txt';
while ($_ = <$fh>) {
print "$.) " . auto_abbreviate($_) . ' ' . $_;
}</lang>


=={{header|Perl 6}}==
=={{header|Perl 6}}==