http://qs321.pair.com?node_id=578492


in reply to Formatting a number

You're going to have a lot of people doing a lot of different versions for this.. and here's mine!
#!/usr/bin/perl use strict; use warnings; print (numformat(1000000),"\n"); print (numformat(123),"\n"); print (numformat(12),"\n"); sub numformat { my ($num) = @_; die "'$num' is not a simple integer" unless $num =~ /^\d+$/; while ($num =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/) {}; return $num; }