> -----Original Message----- > From: Dan Muey > Sent: Wednesday, January 15, 2003 9:19 AM > To: Beau E. Cox; Johnson, Reginald (ECCS); [EMAIL PROTECTED] > Subject: RE: printing number with commas in it > > > > Hi Reggie! > > > > > -----Original Message----- > > > From: Johnson, Reginald (ECCS) [mailto:[EMAIL PROTECTED]] > > > Sent: Tuesday, January 14, 2003 11:32 AM > > > To: '[EMAIL PROTECTED]' > > > Subject: printing number with commas in it > > > > > > > > > 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? > > > > > > > > > Reggie > > > > > > > From the Perl Cookbook (2.17): > > > > sub commify > > { > > my $text = reverse $_[0]; > > $text =~ s/(\d\d\d)(?=\d)(?!\d*.)/$1,/g; > > scalar reverse $text; > This last bit didn't reverse it back so I tried > $text = reverse $text; > And that turned it back around but the regex added no > commas!! Any body have any ideas on this one? I tried : > > $num = '123456'; > &commify("$num"); > > sub commify > { > my $text = reverse $_[0]; > $text =~ s/(\d\d\d)(?=\d)(?!\d*.)/$1,/g; > print "\n$text \n "; > $text = reverse $text; > print "\n$text\n"; > } > And got : ( $_[0] was 123456 ) > > 123456 > > 654321 > > 123456 > > See no commas! What to do for regex ?
It was : $text =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; Mentioned in another post > > } > > > > Baring my typos, this works on a numeric string > > even with a decimal point. > > > > Aloha => Beau; > > > > > > > > -- > > 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] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]