here a sub that i use. $number = 123456 ;
$number = commify($number) ; sub commify { local($_) = shift; 1 while s/^(-?\d+)(\d{3})/$1,$2/; return $_; } -----Original Message----- From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 15, 2003 12:21 PM To: '[EMAIL PROTECTED]' Subject: Re: printing number with commas in it From: "Johnson, Reginald (ECCS)" <[EMAIL PROTECTED]> > I am trying to print a number with commas in it. I cannot find the > correct syntax to do this with printf. I considered using the substr > function but this depends on mealways knowing the size of the number. > Can you help me with this? use Interpolation NUM => 'commify'; $cost = 1245782; print "The cost is $NUM{$cost}.\n"; or (if you do not want the .00) use Interpolation NUM => sub { (my $cost = reverse(shift())) =~ s/(\d{3})/$1,/g; return scalar(reverse($cost)) }; $cost = 1245782; print "The cost is $NUM{$cost}.\n"; (Interpolation.pm may be installed from CPAN and via PPM) Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]