in reply to print statements in perl pakages seem to be masked from STDOUT

I started putting print statements in the methods of the package and they were printing on STDOUT (my console). Suddenly they stopped.
This is indeed odd. What did you change between "it works" and "it doesn't work"? STDOUT and STDERR are available everywhere unless the program specifically closes them or re-opens them to somewhere else - IMO both typically bad ideas - I'm sure there is some kind of exception, but I'd think long and hard before doing either. This is such an odd thing to do that I'd be surprised if that is what you have. However, anything is theoretically possible!

I don't think this is an issue here, but it might be. You should be aware of one fine point. STDOUT is by default buffered. STDERR is by default un-buffered. You can unbuffer STDOUT by adding the line: $|=1; to the top of main and each package. When you do that, any print to STDOUT will appear on the console immediately. The default behavior is to wait until some number of lines are ready for print and then they all appear at once. When the program exits normally, all buffers are flushed. However, I don't think that happens if you CTL-C or kill the process (not a normal program directed exit). If your program is hanging and you CTL-C it, you might not see previous STDOUT prints. Unbuffer STDOUT for debug. This slows down the max print rate, but has the advantage that Error messages (STDERR) and prints to STDOUT will appear in the correct time ordered sequence. Otherwise you might see an warning message and then 4-5 lines later see a STDOUT line that was actually related to the error message.

I must be missing a basic concept about the interaction between an imported module and STDOUT. So my question is: If I want to have a package print to STDOUT, is there something "special" that needs to be done?
Typically, the answer is "No".
  • Comment on Re: print statements in perl pakages seem to be masked from STDOUT
  • Download Code