in reply to Problem while Data Extraction
Hello jpvinny28, and welcome to the Monastery!
In addition to the excellent advice given by GrandFather, above (don’t turn off warnings, avoid subroutine prototypes), here is some general coding advice that will help you in the long run:
Declare variables as late as possible. Your code contains a number of variables that are never used at all. Moreover, @a_str is re-written at the start of each iteration of the while loop, so it would be better to declare it at that point:
my @a_str = split //, $line;
Don’t stringify numbers unless you need to (and in this case, you don’t!):
elsif ($count == 1) { if (...) { $count = 0; ...
Prefer the 3-argument form of open, and use lexical filehandles:
open(my $INFILE, "<", $file) or die "can't open file '$file' for reading: $!";
Choose an indentation style, and stick to it! See perlstyle.
Use consistent variable names. For example, you have a filehandle OUTFILE2 opened for writing on a file named $file3. That’s a maintenance nightmare just waiting to bite you!
Hope that helps,
Athanasius <°(((>< contra mundum
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem with Data Extraction
by jpvinny28 (Novice) on Dec 05, 2012 at 17:07 UTC |