in reply to Re^3: Formatting a number
in thread Formatting a number

Right, I didn't test very much.   :-) This works correctly and appears to be about 10% faster:
sub useSubstr { my $number = shift; my $len = length $number; my $offset = 3; while ( $offset < $len ) { substr $number, -$offset , 0, q{,}; $offset += 4; $len = length $number; } return $number; }

Replies are listed 'Best First'.
Re^5: Formatting a number
by johngg (Canon) on Oct 17, 2006 at 15:38 UTC
    Nice ++. I don't know why I couldn't suss that one out myself. Perhaps I'd worn my brain out :(