This does most of the work for you, but I've left some things for you to do:

<DATA>; my @prev_line; while ( <DATA> ) { my @this_line = split /[,\s]+/; shift @this_line; print join( ", ", map { "$this_line[$_]-$prev_line[$_]" } 0 .. $#t +his_line ), "\n" if @prev_line; @prev_line = @this_line; } __DATA__ date, val1, val2, val3, val4 1/2/2007, 1, 4, 5, 6 1/3/2007, 2, 5, 7, 10 1/5/2007, 5, 6, 8, 11

Output:

2-1, 5-4, 7-5, 10-6 5-2, 6-5, 8-7, 11-10

You may find this version easier to follow (using the same __DATA__ as earlier):

<DATA>; my @prev_line; while ( <DATA> ) { my @this_line = split /[,\s]+/; shift @this_line; if ( @prev_line ) { my @output; for ( 0 .. $#this_line ) { push @output, "$this_line[$_]-$prev_line[$_]"; } print join( ", ", @output ), "\n"; } @prev_line = @this_line; }

That leaves you with the job and handling the files.

I'm sure google will help, and there's always the Perl documentation.

update: omitted __DATA__ first time round
update^2: added second example


In reply to Re^2: performing calculation in cells in a file by FunkyMonk
in thread RE: performing calculation in cells in a file by gsaray101

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.