N'th: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: Fix link: Perl 6 --> Raku) |
||
Line 1,961: | Line 1,961: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{Trans| |
{{Trans|Raku}} |
||
Requires Perl 5.10 or newer for the Defined OR operator (//). |
Requires Perl 5.10 or newer for the Defined OR operator (//). |
||
<lang perl> |
<lang perl>use 5.10.0; |
||
my %irregulars = ( 1 => 'st', |
|||
2 => 'nd', |
2 => 'nd', |
||
3 => 'rd', |
3 => 'rd', |
||
Line 1,977: | Line 1,978: | ||
sub range { join ' ', map { nth($_) } @{$_[0]} } |
sub range { join ' ', map { nth($_) } @{$_[0]} } |
||
print range($_), "\n" for ([0..25], [250..265], [1000..1025]); |
print range($_), "\n" for ([0..25], [250..265], [1000..1025]);</lang> |
||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th |
|||
Same as Perl 6 |
|||
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th |
|||
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre> |
|||
Alternatively, can use a library. |
|||
{{libheader|Lingua::EN::Numbers::Ordinate}} |
{{libheader|Lingua::EN::Numbers::Ordinate}} |
||
<lang |
<lang perl>use Lingua::EN::Numbers::Ordinate 'ordinate'; |
||
foreach my $i (0..25, 250..265, 1000..1025) { |
foreach my $i (0..25, 250..265, 1000..1025) { |
||
print ordinate($i),"\n"; |
print ordinate($i),"\n"; |