[Princeton-pm] processing cells in a file
mike smith
gsaray101 at yahoo.com
Wed Aug 22 10:56:37 PDT 2007
there is a csv file like this:
date, val1, val2, val3, val4 etc
1/2/2007, 1, 4, 5, 6
1/3/2007, 2, 5, 7, 10
1/5/2007, 5, 6, 8, 11
what I need to do is, calculate the differnce between
cells for each column and write it to a file. for
example, since there is no previous value to row one,
write first row to a file. then subtrack second raw
values from the first row values and write the output
to the second line in ouptput file - (2-1, 5-4, 7-5,
10, 6). Third raw in the output file should be, 5-2,
6-5, 8-7, 11-10 and so on. I have the code below but
having trouble formatting the output file. The ouput
file should be like the first raw of the input file,
the other lines should start with time stamp in the
first column of input file and symetric cell
subtration. Can anybody look at this and provide
insight?
Code: ( perl )
#!/usr/local/bin/perl
use Data::Dumper;
open(FILE,"<test.csv");
$row=-1;$col=-1;
while (<FILE>) {
chomp;
if (/^[0-9]/) {
chomp;
$row++;
$col = -1;
foreach $char (split /,/) {
$col++;
$cell[$row][$col]=$char;
}
}
}
for $i (0..$#cell) {
$aref = $cell[$i];
$n = @$aref - 1;
for $j (0..$n) {
print "$cell[$i][$j],";
}
print "\n";
}
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting
More information about the Princeton-pm
mailing list