1: #!/usr/bin/perl -ps
2: # This one is a small improvement of the code that adds commas
3: # to numbers. It has the advantage of not breaking tabular
4: # format (such as the output of `ls` and `du`)
5: # Adopted from Perl Monks "How do I add commas to a number?"
6: #
7: # Use -r switch to cancel the alignment
8: #
9: # Example: ls -l | ,
10:
11: unless($r) { while (s/\s (?=\d)/ 0/g) {} }
12: $_=reverse;
13: s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
14: $_=scalar reverse;
15: unless($r) { while (s/\s[0,](?=[\d,])/ /g) {} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Add coma to numbers, a bit better
by japhy (Canon) on Mar 02, 2001 at 23:04 UTC | |
by danger (Priest) on Mar 03, 2001 at 02:01 UTC | |
by japhy (Canon) on Mar 03, 2001 at 02:12 UTC | |
by danger (Priest) on Mar 03, 2001 at 02:35 UTC | |
by fundflow (Chaplain) on Mar 03, 2001 at 13:49 UTC | |
|
Re: Add coma to numbers, a bit better
by aardvark (Pilgrim) on Mar 04, 2001 at 02:05 UTC | |
by fundflow (Chaplain) on Mar 04, 2001 at 22:24 UTC | |
|
Re: Add coma to numbers, a bit better
by buckaduck (Chaplain) on Mar 10, 2001 at 04:18 UTC | |
|
Re: Add commas to numbers, a bit better
by Deven (Novice) on Feb 25, 2022 at 04:06 UTC |