Comma quibbling: Difference between revisions
Content deleted Content added
Promote from draft to full task status |
Add Perl 5. |
||
Line 155: | Line 155: | ||
quibble ["ABC"; "DEF"; "G"] |
quibble ["ABC"; "DEF"; "G"] |
||
quibble ["ABC"; "DEF"; "G"; "H"]</lang> |
quibble ["ABC"; "DEF"; "G"; "H"]</lang> |
||
=={{header|Perl}}== |
|||
{{trans|Perl 6}} |
|||
<lang perl>sub comma_quibbling(@) { |
|||
my @A = @_; |
|||
return "{$_}" for |
|||
@_ < 3 ? join(' and ', @A) : |
|||
join(',', @A[0..@A-2]) . ' and ' . $A[-1]; |
|||
} |
|||
print comma_quibbling(@$_), "\n" for |
|||
[], [qw(ABC)], [qw(ABC DEF)], [qw(ABC DEF G H)];</lang> |
|||
{{out}} |
|||
<pre>{} |
|||
{ABC} |
|||
{ABC and DEF} |
|||
{ABC,DEF,G and H}</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |