* How can I output my numbers with commas added?
+ a lot of people have asked me to un-delete the original subroutine
+ a couple of english fixes
Index: perlfaq5.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq5.pod,v
retrieving revision 1.21
diff -u -d -r1.21 perlfaq5.pod
--- perlfaq5.pod 17 Jul 2002 17:51:36 -0000 1.21
+++ perlfaq5.pod 17 Aug 2002 19:35:11 -0000
@@ -288,11 +288,19 @@
=head2 How can I output my numbers with commas added?
-This one from Benjamin Goldberg will do it for you:
+This subroutine will add commas to your number:
+
+ sub commify {
+ local $_ = shift;
+ 1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
+ return $_;
+ }
+
+This regex from Benjamin Goldberg will added commas to numbers:
s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
-or written verbosely:
+It is easier to see with comments:
s/(
^[-+]? # beginning of number.