#!/usr/bin/perl -ps # This one is a small improvement of the code that adds commas # to numbers. It has the advantage of not breaking tabular # format (such as the output of `ls` and `du`) # Adopted from Perl Monks "How do I add commas to a number?" # # Use -r switch to cancel the alignment # # Example: ls -l | , unless($r) { while (s/\s (?=\d)/ 0/g) {} } $_=reverse; s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; $_=scalar reverse; unless($r) { while (s/\s[0,](?=[\d,])/ /g) {} }