Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: How to transform the data with Perl

by ELISHEVA (Prior)
on Oct 06, 2009 at 03:25 UTC ( [id://799375]=note: print w/replies, xml ) Need Help??


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

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

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

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found