0: #!/usr/bin/perl -ps
1: # This one is a small improvement of the code that adds commas
2: # to numbers. It has the advantage of not breaking tabular
3: # format (such as the output of `ls` and `du`)
4: # Adopted from Perl Monks "How do I add commas to a number?"
5: #
6: # Use -r switch to cancel the alignment
7: #
8: # Example: ls -l | ,
9:
10: unless($r) { while (s/\s (?=\d)/ 0/g) {} }
11: $_=reverse;
12: s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
13: $_=scalar reverse;
14: unless($r) { while (s/\s[0,](?=[\d,])/ /g) {} } In reply to Add commas to numbers, a bit better by fundflow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |