gaseous1 has asked for the wisdom of the Perl Monks concerning the following question:
I am printing in a WHILE loop, using a text database file that is tab delimited. There is a header line, followed by several thousand data lines. Each record contains 21 fields.
When I print in the WHILE loop, very strange things happen. I am printing to STDOUT and to an output file. The STDOUT is currently used for debugging, but will eventually be used as a progress indicator. The output file will be used to store summarized data from the original file.
The madness happens with the print statements. The behavior is similar regardless of printing to STDOUT or to a file. The first line which the program evaluates in the input file, everything prints as expected. On subsequent iterations, the **only** item that prints is the $line value (actually, I think it is the $_ value). Nothing else prints.
I've looked far and wide for an answer and can't find one. Why is this happening? How do I rectify it?
#!/usr/bin/perl use strict; use warnings; my $in_fileName = "/Users/me/test.txt"; my $out_fileName = "/Users/me/test-out.txt"; my $infi; my $oufi; my @data_array; my $line; my $ctr; my $txt1 = " Field:\t"; open $infi, "<" . $in_fileName or die $!; open $oufi, ">" . $out_fileName or die $!; while(<$infi>) { $line = $_; chomp($line); @data_array = split(/\t/, $line); for ($ctr = length[@data_array]; $ctr >= 0; $ctr--) { print {*STDOUT} $txt1, $data_array[$ctr], "\t", $ctr + 1, "\t" +, $., "\n"; } print {$oufi} "Record: ", $line,"\n"; } close $oufi; close $infi;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing in a WHILE loop
by Athanasius (Archbishop) on May 27, 2014 at 04:19 UTC | |
by gaseous1 (Novice) on May 27, 2014 at 05:34 UTC | |
|
Re: Printing in a WHILE loop
by NetWallah (Canon) on May 27, 2014 at 04:20 UTC | |
by choroba (Cardinal) on May 27, 2014 at 08:03 UTC | |
by gaseous1 (Novice) on May 27, 2014 at 15:03 UTC | |
by gaseous1 (Novice) on May 27, 2014 at 05:32 UTC | |
|
Re: Printing in a WHILE loop
by GrandFather (Saint) on May 27, 2014 at 12:00 UTC | |
by gaseous1 (Novice) on May 27, 2014 at 15:00 UTC | |
by gaseous1 (Novice) on May 28, 2014 at 04:55 UTC | |
|
Re: Printing in a WHILE loop
by wjw (Priest) on May 27, 2014 at 04:54 UTC | |
by gaseous1 (Novice) on May 27, 2014 at 05:39 UTC | |
|
Re: Printing in a WHILE loop
by GrandFather (Saint) on May 28, 2014 at 07:04 UTC |