From gsaray101 at yahoo.com Wed Aug 22 10:56:37 2007 From: gsaray101 at yahoo.com (mike smith) Date: Wed, 22 Aug 2007 10:56:37 -0700 (PDT) Subject: [Princeton-pm] processing cells in a file Message-ID: <884427.8446.qm@web51902.mail.re2.yahoo.com> 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,") { 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 From timothy.helck at gmail.com Thu Aug 23 08:44:48 2007 From: timothy.helck at gmail.com (Timothy Helck) Date: Thu, 23 Aug 2007 11:44:48 -0400 Subject: [Princeton-pm] processing cells in a file Message-ID: <780239480708230844j5ee2b8do7cb55f1d24f92ff6@mail.gmail.com> I haven't tried running your code, so forgive me if I'm way off here... It sounds like you might want to try writing to a format. Something like: ========================================= my ($date, $col1, $col2, $col3); format STDOUT = @<<<<<<<<<<<<<<<<@##########@##########@########## $date, $col1, $col2, $col3 . in your loop you would set the above variables to the correct values and then: write STDOUT; ========================================= google "perl format" if this sounds like what you want. Hope it helps. Regards, Tim On 8/22/07, princeton-pm-request at pm.org wrote: > > Send Princeton-pm mailing list submissions to > princeton-pm at pm.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.pm.org/mailman/listinfo/princeton-pm > or, via email, send a message with subject or body 'help' to > princeton-pm-request at pm.org > > You can reach the person managing the list at > princeton-pm-owner at pm.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Princeton-pm digest..." > > > Today's Topics: > > 1. Re: processing cells in a file (mike smith) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 22 Aug 2007 10:56:37 -0700 (PDT) > From: mike smith > Subject: Re: [Princeton-pm] processing cells in a file > To: princeton perl group > Message-ID: <884427.8446.qm at web51902.mail.re2.yahoo.com> > Content-Type: text/plain; charset=iso-8859-1 > > 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," > $row=-1;$col=-1; > while () { > 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 > > > ------------------------------ > > _______________________________________________ > Princeton-pm mailing list > Princeton-pm at pm.org > http://mail.pm.org/mailman/listinfo/princeton-pm > > End of Princeton-pm Digest, Vol 13, Issue 1 > ******************************************* > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/princeton-pm/attachments/20070823/9b6e7aac/attachment.html