View Single Post
  #1 (permalink)  
Old December 21st, 2006, 08:38 AM
crmpicco crmpicco is offline
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default scalar and reverse

Can anyone assist in explaining what the function 'commafy' is doing?
there are a few things in there i dont understand, i.e. the scalar and reverse pieces of code.
my usage of the function:

Code:
comm(sprintf("%.2f", $byviewprice{$view}))
a typical example of the value of '$byviewprice{$view}' is 501.

Code:
sub comm {

    my $text = shift;

    $text = reverse $text;
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;

    if ($text eq "") {
        $text = 0;
    }

    return scalar reverse $text;
}
www.crmpicco.co.uk
www.ie7.com
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote