[Princeton-pm] processing cells in a file

Timothy Helck timothy.helck at gmail.com
Thu Aug 23 08:44:48 PDT 2007


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 <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 <gsaray101 at yahoo.com>
> Subject: Re: [Princeton-pm] processing cells in a file
> To: princeton perl group <princeton-pm at pm.org>
> 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,"<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
>
>
> ------------------------------
>
> _______________________________________________
> 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 


More information about the Princeton-pm mailing list