Bavie has asked for the wisdom of the Perl Monks concerning the following question:

I am new to PERL and I am not a regular programmer. I need help in trying to sum, and also find averages. I have data as shown below 0 4/2/2007 6:00:15 21615 62 2 2 4 1 4/2/2007 6:00:55 21655 60 2 2 4 2 4/2/2007 6:01:15 21675 65 20 3 4 3 4/2/2007 6:02:15 21735 65 20 3 4 4 4/3/2007 6:00:00 21600 65 20 3 4 5 4/3/2007 6:00:15 21615 62 2 2 4 6 4/3/2007 6:00:55 21655 60 2 2 4 7 4/3/2007 6:02:15 21735 65 20 3 4 Cols 2, 3, and 4 are Date, time (in hours) and time (in seconds. The result I want is the sum (col 6) and average (cols 5 and 7) for 2 minute intervals by day. The result should look like ... 0 4/2/2007 6:00:00 62.33 8 2.33 1 4/2/2007 6:02:15 65 20 3 2 4/3/2007 6:00:00 62.33 8 2.33 3 4/3/2007 6:02:15 65 20 3 Thanks in advance to anyone who can help me with this...

Replies are listed 'Best First'.
Re: Summing Lines
by codeacrobat (Chaplain) on Apr 07, 2009 at 06:36 UTC
Re: Summing Lines
by CountZero (Bishop) on Apr 07, 2009 at 06:19 UTC
    Please put your data in <code> ... </code> tags so we can have some idea what they look like without having to guess the layout.

    Is each line of data on a separate line or are they just streaming all along?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Summing Lines
by apl (Monsignor) on Apr 07, 2009 at 08:02 UTC
    What have you written so far?

    Are you having problems

    • reading the record
    • parsing the record
    • doing the calculations
    • storing the results
    • displaying the results
    On the other hand, if you want us to write the program for you may have come to the wrong place...