Abbreviations, automatic: Difference between revisions
m
→{{header|Perl 6}}: move string building out of the sub (separation of concerns)
m (removed the __TOC__ (no longer needed).) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: move string building out of the sub (separation of concerns)) |
||
Line 282:
Saving the "Days of Week, Also Known As" table to a local file DoWAKA.txt. Note: lines that have duplicate day names will get ∞ as the minimum number of characters, as there in no amount of characters that can be entered to distinguish the days uniquely. It is somewhat unclear as to what is meant by "return a null string". I have chosen to return Nil.
<lang perl6>sub auto-abbreviate ( Str $string ) {
return Nil unless my @days = $string.words;
my $max = @days».chars.max;
for 0 .. $max {
return
return
}
}
# Testing
say ++$, ') ', .&auto-abbreviate, ' ', $_ for './DoWAKA.txt'.IO.
{{out|Sample abbreviated (heh) output}}
<pre>1) 2
2) 2
3) 4
4) 2
5) 5
...
90) ∞
91) 2
92) 2
93) 2
94) 5
95) 1
96) 7
97) 12
98) 4
99) 2
=={{header|REXX}}==
|