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