|No such thing as a small change|
Odd behaviour from print statementby periapt (Hermit)
|on Jan 18, 2005 at 20:52 UTC||Need Help??|
periapt has asked for the
wisdom of the Perl Monks concerning the following question:
I have been experiencing some odd behaviour that I've tracked down to a print statement (I think). Essentially, the print statement (I/O buffer?) doesn't output specific lines. Every line after the first line in fact although it always prints the first line. When run against different data sets, the loop will not drop lines consistently from set to set but will consistently drop data from the same data set on multiple runs.
The data is output to file if a filename is specified on the command line and to STDOUT if no filename is given.
The problem seems to occur only when I specify the file name on the command line. It does not occur if when printing to STDOUT. I can also correctly redirect the output from STDOUT into a file.
I've tried ...
Additional info & suggestions from various monks ...
System specs ...
At this point, I'm stumped. Any suggestions will be most appreciated.
Update01: added some additional info and the results of some monk suggestions.
Update02: I solved it. Read operator error :o( Under certain circumstances, the program makes a a second pass through the loop. The open statement then clobbers the file and only inputs a portion of the remaining records. The open mode should be append ">>" not create ">". Thanks for all the great suggestions though. I learned a few things.
use strict; use warnings; use diagnostics;