Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: "Commifying" a number

by hiseldl (Priest)
on Dec 12, 2002 at 16:49 UTC ( [id://219370]=note: print w/replies, xml ) Need Help??


in reply to "Commifying" a number

    I'm interested to know if there's a "simpler" way to do this - ideally getting rid of the super-hideous while loop

How about a recursive solution?

sub commify { my($num) = @_; return $num if length($num)<4; return commify(substr($num,0,-3), $len).",".substr($num,-3,3); }
...no super-hideous while loop there, and no regex compilation either. ;-)

The only downside is that this only works for integers.

--
hiseldl
What time is it? It's Camel Time!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219370]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found