in reply to Re^2: How to transform the data with Perl
in thread How to transform the data with Perl---Solved !!!

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

Replies are listed 'Best First'.
Re^4: How to transform the data with Perl
by hujunsimon (Sexton) on Oct 06, 2009 at 02:12 UTC

    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 !

      Thanks for fixing the post and welcome to PerlMonks!

      Congratulations on getting your program to work! Since you've said comments are welcome, I'd like to give you some feedback that will help you in future programs.

      • Using warnings is good. Even better is to use strict and warnings! All of your scripts should begin with these two lines:
        use strict; use warnings;
      • When you turn on strict, you will no doubt see a lot of complaints from the Perl compiler. This is because you haven't declared your variables using my or our.
        my $file =... open (TEMP, $file) or die("Error: cannot open $file\n"); my $outfile =...
        Declaring your variables will save you a great deal of time. It is particularly good at preventing mistakes caused by assigning values to a variable using one name and then later on working with the variable using a slightly different name. For example, you might start your script using $counter_A and later on use $cuonter_A, $counter_a, $counter_1, $Counter_A or any other number of small variations. The combination of strict and variable declarations would prevent that.
      • When you find yourself naming variables like $counter_A, $counter_B, $counter_C it is time to start thinking about arrays. For example, my @counter = (0,0,2). See perldata for more information.
      • Always check open for errors. You did it on your first open (which is good), but not on later ones.
      • Be consistent about indenting. For the most part you are, except at the very end of the while loop where you place the last three lines at the same indentation as while. Since they are inside the while loop they should be indented like the lines at the top of the while loop. Indenting is a very important visual clue about which control flow statement controls which block of code. It lets us quickly skim code and know where to focus attention when there are problems.
      • You don't need to explicitly select OUTPUT as an output stream if you are using print OUTPUT ... to do your prints. Lines that don't do any work won't make your code break, but they can be distracting, especially when you are trying to debug code and need to get rid of anything not related to the problem.

      Best of luck on your programming journey (all of 36 hours so far!) and welcome again to PerlMonks!

      Best, beth

        Beth,

        Thank you very much for the comments, i'm really appreciated. now i'm revising my program and try to make it better !

        cheers,

        Simon
      ...i have corrected them now... - sorry to be the bearer of bad tidings, but the format is no better - the unbelievably long single data line remains :-((

      A user level that continues to overstate my experience :-))