in reply to How to transform the data with Perl---Solved !!!

What is link_no? Where are the commas in your Comma Separated Values? Time_interval seems to be a 15-minute part of a day, right? If you want to keep the data structure as simple as possible you can still store all data into one array, just add 96 to the index if you want to access the weekend data.

For a clean maintainable solution you have to use a multi-dimensional array, something like this:

#Store an entry: $speed[1][1]['weekday']= 32.61712; #or when you load values from a CSV file (I assume all values on one l +ine: my $line=<csvfile>; my @speeds= split $line; my $link_no=1; my $i=1; my $day='weekday'; foreach (@speeds) { $speed[$link_no][$i++][$day]= $_; }
If you want to have each day in the database instead of only data for 'weekday' and 'weekend', you can still use above and then either copy the 'weekday' data to the 'monday', 'tuesday' slots or copy only the link (i.e. $speed[$link_no][$i++]['monday']= $speed[$link_no][$i++]['weekday'];, which would share the data, i.e. if you change data in the 'weekday' set, you also change it in the 'monday' set)

Replies are listed 'Best First'.
Re^2: How to transform the data with Perl
by hujunsimon (Sexton) on Oct 05, 2009 at 14:41 UTC

    sorry....... i have changed the format of my post.

    Jethro: the common is at every 192 of speed value, i trucated the dataset and only put one link speed record here, there are 66 links in the dataset. sorry for the confusion. thanks for your suggestion, i will give it a try now.

      It seems you do not understand the problem with your post format. Perhaps you may have noticed that to see the far right of your post, people need to scroll many, many screenfuls? This is considered very impolite and the solution is to surround that one very, very long line with <code> tags, like this:
      <code> 32.61712_29.23591_24.84628_22.84434_30.59529_28.76819_35.03523_30.9736 +7_30.5064_38.87624_49.87962_51.24486_47.32718_48.00002_51.71957_44.31 +798_39.75034_48.64877_30.88166_36.76909_54.46225_38.02563_30.29589_37 +.91334_21.44945_28.95672_22.03353_21.29655_23.84956_19.28472 </code>

      Using code tags causes the text to wrap around. We still know that this is one long line because each wrapped line begins with a red + sign. The red plus doesn't show up in your input window though because it is still one long line there. Please, please, do what I did above to your original post so you won't annoy people further.

      Best, beth

        Thanks for all advices and sorry for being an annoyance for the format of my post, :(. i have corrected them now. i'm a newbie in this forum, but try to learn the etiqutte quickly.

        thank you for the help, i have made my program working now. it's really cool.

        here is part of my code:
        #!/usr/bin/perl use warnings; $file =... open (TEMP, $file) or die("Error: cannot open $file\n"); $outfile =... open (OUTPUT,">$outfile"); select(OUTPUT); # explicitly select the new file for output #declare variables $counter_A=0; $counter_B=0; #counter for time of the day $counter_C=2; #counter for day of the week,date starts on + tuesday @interval = (1..35040); #15 mins interval over a year 365 days $nline = "\n"; $scomma = ", "; $i = 0; while ($line = <TEMP>) { @column = split (/,/,$line); @speed = split (/_/,$column[5]); foreach $timeint (@interval) { if ($counter_A==4) { $counter_A = 0; $counter_B++; if ($counter_B==24) {$counter_B = 0; $counter_C++; $i = 0; if (($counter_C>=6) && ($counter_C<8)) { $i = 96; } if ($counter_C==8) { $counter_C = 1; } } } print OUTPUT trim($column[0]).$scomma.trim($column[1]).$scomma.$speed[ +$i].$nline $counter_A++; $i++; } }

        the program will read the csv file and place the speed data according to time of the day and day of the week.

        i know the code can be more simplified, but it does exactly the job i wanted, also considering i only learned perl for 36 hours, so i'm pretty happy, :-) !

        thanks for all PerlMonks, any comments will be welcomed !