Abbreviations, automatic: Difference between revisions

Content deleted Content added
Steenslag (talk | contribs)
m →‎{{header|Ruby}}: shaved off a line
SqrtNegInf (talk | contribs)
m →‎{{header|Perl}}: strict compliant
Line 1,729: Line 1,729:
Output is the same as for Perl 6.
Output is the same as for Perl 6.
{{trans|Perl 6}}
{{trans|Perl 6}}
<lang perl>use utf8;
<lang perl>use strict;
use utf8;
binmode STDOUT, ":utf8";
binmode STDOUT, ":utf8";


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