Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: "Commifying" a number

by hiseldl (Priest)
on Dec 12, 2002 at 16:49 UTC ( #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? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-05-29 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?