Nov 30, 2017, 1:35 AM
Post #2 of 3
Re: [redheards] help with this code
[In reply to]
there are numerous errors in your code (see below). It would be good it you explained what exactly you're trying to do, as it would make it easier for us to help you.
Unless you've shown only part of your code, you haven't opened a file yet, so the $FH filehandle is not defined. So you need to open the file first.
In addition, if $FH was properly defined, I very much doubt that you really want to slurp the whole content of the file into the @line array for each iteration of your for loop. Either you want to read only one line, and then you need to read the file in scalar context:
or you want the whole file to land into your array, in which case you should do that outside of the loop, i.e. before the for loop statement.
You don't have a $line variable anywhere, so it can't be defined.
The $count variable is refined within the loop and therefore reset at each iteration within the for loop, so that $line[$count] will always return the first line of the array, probably not what you want. Same problem with the $counter variable. Finally, you're never using the $i variable within the loop, so that's also likely to be an error compared to what you want.
Again, besides pointing to the errors, I can't help much further and tell you how to fix the issues, because I am not sure what you're trying to achieve. Please explain in plain English what your program is intended to do.