Re: perlfaq5: "How can I output my numbers with commas added?"

[email protected] (_brian_d_foy) Mon, 07 Mar 2005 18:22:53 -0500
Newsgroups perl.perlfaq.workers
Message-ID <070320051822539990%[email protected]>
[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <20050302071103.GA16570@klangraum>, A. Pagaltzis
<[email protected]> wrote:

> Maybe the following could be added to the FAQ, possibly as the
> canonical example?
> 
>     sub commify {
>         scalar reverse join ',',
>         unpack '(A3)*',
>         scalar reverse shift;
>     }

I looked at your example, but found that it doesn't work. It doesn't
handle negative or fractional numbers. You assume that every
character in the string is a digit, and that is not always the case.

Although this is an interesting use of pack(), I don't want to add
it to the answer since it is more complicated than the other answers
but doesn't have as much value.

-- 
brian d foy, [email protected]