Path: utzoo!attcan!uunet!lll-winken!elroy.jpl.nasa.gov!decwrl!orc!mipos3!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Inserting commas in numbers Message-ID: <1990Mar1.170610.4475@iwarp.intel.com> Date: 1 Mar 90 17:06:10 GMT References: <2450@bnr-fos.UUCP> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 27 In-Reply-To: friedman@chekov.UU.NET (Barry Friedman) In article <2450@bnr-fos.UUCP>, friedman@chekov (Barry Friedman) writes: | After getting tired of looking at 10 digit+ numbers in a report, | I came up with the following routine to insert commas. | | Unfortunately, I couldn't figure out how to use split to split groups | of three so this is kind of long. Hope you find it useful. | | ex. | &commas("9999999"); returns 9,999,999 [code deleted] How about: sub commas { local($_) = @_; while (s/(.*)(\d)(\d\d\d)/$1$2,$3/) {;} $_; } OK, so I had some practice in Snobol... :-) for('Snobol','Perl'){print"Just another $_ hacker,\n";} -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/