Commatizing numbers: Difference between revisions
m
→{{header|Perl 6}}: Style tweaks, DRY, separation of concerns; same output
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Style tweaks, DRY, separation of concerns; same output) |
|||
Line 584:
=={{header|Perl 6}}==
<lang perl6>
{
say " After: ", .[1] ?? .[0].&commatize( |.[1] ) !! .&commatize;
}
sub commatize($s, :$at = 0, :$ins = ',', :$by = 3) {
▲ say "Before: ", $s;
▲ / <[1..9]> <[0..9]>* /,
*.flip.comb(/<{ ".**1..$by" }>/).join($ins).flip;
}</lang>
|