develooper Front page | perl.beginners | Postings from March 2002

How to handle a currency sign in a calulation

Thread Next
From:
Bruce Ambraal
Date:
March 21, 2002 04:16
Subject:
How to handle a currency sign in a calulation
Message ID:
sc99ea92.047@cct.org.za
The following programs calculates sum totals of the values in file (Values.dat).

Values.dat:
---------------
$30,45
$0,50


How do I  handle the $ sign infront of the values.
I want the $ sign in the result when calulating sum of these values. 
In my program I left out the $ sign cause I dont know.

--------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
open(INPUT, "Values.dat") || die;
my $value;
while (<INPUT>) {
   if (/\d*,\d{3}/) {s/,//; $value += $_; }
   else {print "warning: line of unexpected format ($_)\n";}
}
1 while( $value =~ s/(\d*,)(\d{3})(?=\.|,|\z)/$1,$2/ );
print $value;
close(INPUT);
-------------------------------------------------------------------------------------------------------


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About