This is a random slice of a random image found somehwere in my blog...
Gibberations by ...
Cyber-Gish | GishTeq
Gibberations RSS feed
603 entries
909 comments
Monday / May 26th / 2003
Commify text...
Here's a little Perl snippet which will place commas in any number string right where they belong:

sub commify
{
    my $text = reverse $_[0];
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
    return scalar reverse $text;
}
So for example, by calling commify("13245766") the value "13,245,766" will be returned.

All the little commas right exactly at the correct positions using a simple regular expression. Pretty amazing language that Perl is. Does it make sense?


~ Posted at 09:47 AM | Computers and stuff
  
So far there are 0 comments. Be the very first person to add a comment:

Name:


Email Address (optional):
(spam-protected)

URL (optional):
with "http://"

  What's this?

Comments:
HTML is allowed.Spell checker?


"God will not suffer man to have the knowledge of things to come; for if he had prescience of his prosperity he would be careless; and understanding of his adversity he would be senseless..."  - - Saint Augustine, .


Navigate
From here you can quickly navigate to the previous archived entry («), or to the next archived entry (») or simply go back to the main page.
Comments
Have a look below at the comments of others or be the first one to add a comment of your very own for this entry.