in reply to data manipulation

Here's what I worked out. It does actually work even though it looks like crap and I'm sure one of you can probably cut out half of the code. Please feel free to show me a better way to do this.
open OUT, ">$Output_Directory/sitescope.dat" or die "Can't open OUTPUT + file: $!"; foreach (@data) { $counter++; @tmp = split(/\t/); ($time,$date) = split(/ /,$tmp[0]); $date =~ s/2003/03/g; $time = substr($time,0,5); $mday = substr($date,3,2); ($hour,$min) = split(/:/,$time); $mod = int($min/5); if ($mod != $last_mod) { print OUT "$last_date\.$last_time\t"; foreach (1..5) { $seconds = $seconds{$_}/$counter; printf OUT "%1.2f\t",$seconds; $seconds{$_}=0; } print OUT "\n"; $counter=0; } foreach (@tmp[1..5]) { $place++; $seconds{$place} += ($_/1000); } $place=0; $last_mod = $mod; $last_date = $date; $last_time = $time; } close OUT;
Original data:
08/08/03.07:55  1.61    1.158   0.71    0.209   0.535   
08/08/03.07:57  1.094   0.887   0.96    0.126   0.322   
08/08/03.07:59  5.131   0.986   1.029   0.095   0.251   
08/08/03.08:01  1.071   1.274   0.638   0.197   0.347   
08/08/03.08:03  1.166   0.984   0.598   0.092   0.583   

Chunked data:

08/08/03.07:59  2.39    0.94    0.80    0.11    0.30    
08/08/03.08:03  2.31    1.60    1.02    0.20    0.61    

Replies are listed 'Best First'.
Re: Re: data manipulation
by Not_a_Number (Prior) on Aug 08, 2003 at 16:58 UTC

    Among other problems:

    ($time,$date) = split(/ /,$tmp[0]);

    I don't think this line is doing what you think its doing. The contents of @tmp are something like

    (08/08/03.08:01, 1.071, 1.274, 0.638, 0.197, 0.347)

    ...and you are trying to split the first element in the array, 08/08/03.08:01, on a non-existent space. This means that $time contains the whole string, while $date is empty!

    I think you need something like this:

    my ( $date, $time ) = split( /\./, @tmp[0] );

    And note that I've changed the order of your scalar variables around!

    my best advice to you is:

    use strict; use warnings;
    dave
      ($time,$date) = split(/ /,$tmp[0]);
      This is actually coming from the raw data file before any manipulation which looks like this:
      10:40:32 08/08/2003 good website servername 8.32 sec, + 9 steps, 241K total, 35 images 16:72472 200 8328 ok 1557 662 1275 582 + 517 1129 1053 962 591

      I convert the time/date to the new format for use with Ploticus (an opensource graphing tool which I love) which likes to see a period between the two.

      Edit by tye, change PRE to CODE around long lines