perlfaq5: How can I output my numbers with commas added?
[email protected] (pizza)
| Newsgroups | perl.perlfaq.workers |
|---|---|
| Message-ID | <[email protected]> |
this is the shortest regex i can come up with that seems to work all in one
line.
s/([+-])?(\d{1,3})(?=(\d{3})+)/$1$2,/g;
------------------------------
#!/usr/bin/perl -l
$_ = "-10,000000";
s/([+-])?(\d{1,3})(?=(\d{3})+)/$1$2,/g;
print;
------------------------------
it seems to handle a leading +/- and existing commas
feedback appreciated.
pizza