Just escape the $ by prepending a backslash.  \$

-----Original Message-----
From: Bruce Ambraal [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 4:13 AM
To: [EMAIL PROTECTED]
Subject: How to handle a currency sign in a calulation


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);
----------------------------------------------------------------------------
---------------------------


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to