Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

  (email not shown publicly)
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Wednesday February 11, 2004
12:03 PM


[ #17359 ]

I found this lovely snippet of code while fixing* a broken script. I especially love how as a side effect it removes the spaces from $_.

sub Commify
  s/ //g;
        my $delimiter = ',';
        my($n,$d) = split /\./,shift,2;
        my @a = ();
        while($n =~ /\d\d\d\d/)
                $n =~ s/(\d\d\d)$//;
                unshift @a,$1;
        unshift @a,$n;
        $n = join $delimiter,@a;
        $n = "$n\.$d" if $d =~ /\d/;
        return $n;

*The sort of fixing that is done with rm.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.