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

I wish I could tell you what happened. I added print statements in the package, I was seeing them in the output, I added a print statement, I stopped seeing any output from the package, I removed the recently addded print statement, I could no longer see any output from the package

Years ago I remembered that I tried to print in a package and it did not work, I wrote it off to scope and moved on with debug objects. My question is: should I expect a print statement to provide output on STDOUT as it does when the print statement is in the main body of the .pl?

If the answer is "no". can you point me at something that will help me output data from the package so I can see what is happening inside that code?

  • Comment on Re^2: print statements in perl pakages seem to be masked from STDOUT

Replies are listed 'Best First'.
Re^3: print statements in perl pakages seem to be masked from STDOUT
by stevieb (Canon) on Mar 07, 2018 at 17:07 UTC
    My question is: should I expect a print statement to provide output on STDOUT as it does when the print statement is in the main body of the .pl?

    You should definitely see the print statements on STDOUT from a module, just like the script, unless the module is hijacking STDOUT somehow per Corion's post above.

Re^3: print statements in perl pakages seem to be masked from STDOUT
by 1nickt (Canon) on Mar 07, 2018 at 17:32 UTC

    The answer is a conditional "yes" as described by Corion and stevieb. If you are suspicious that STDOUT has been overridden, you could always open your own filehandle and print your debug statements to a file. But if

    print {$self->{fileout}} "what I want to print\n";
    does not work, then you may not have opened your filehandle successfully, or it may not be stored in the variable you think it is. Did you check?


    The way forward always starts with a minimal test.
      Thank you, I will check that and report back.