[ic] Per Question - Off Topic

Jack Lauman interchange-users@lists.akopia.com
Sat Jun 16 14:25:01 2001


I get a currency exchange report emailed to me every night with the
closing rates on Wall Street and want to convert it to a csv file.

I need to strip the leading and trailing spaces from two numeric
(floating point) fields: $usd_unit and $units_usd.

Where is what I have now... I would appreciate any help with this
problem.  


use strict;
use vars qw($date $time $cur_sym $cur_desc $usd_unit $units_usd);

use POSIX qw(strftime);
$date = strftime "%Y-%m-%d", localtime;
$time = strftime "%H:%M:%S", localtime;

open (OUTFILE, ">", "currency.csv") || die "Can not open currency.csv
for writing";

printf STDERR "Reading currency file";
open (INFILE, "curtest") || die "Can not open /var/spool/mail/currency
for reading";

while (<INFILE>) {
	
	$date;
	$time;
	$cur_sym = substr($_, 0, 3);
	$cur_desc = substr($_, 4, 28);
	while ($cur_desc =~ /\s$/) {
	    chop($cur_desc);
	}    
	$usd_unit = substr($_, 35, 19);
	while ($usd_unit =~ /\s$/) {
	    chop($usd_unit);
	}    
	$units_usd = substr($_, 57, 19);
	while ($units_usd =~ /\s$/) {
	    chop($units_usd);
	}    

	printf OUTFILE "%s\,%s\,%s\,%s\,%s\,%s\n", $date, $time, $cur_sym,
$cur_desc, $usd_unit, $units_usd;
	
}
close(INFILE);
close(OUTFILE);
print STDERR "\n";

1;

Thanks,

Jack