CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to print output to STDOUT

 



naven8
Novice

Apr 9, 2012, 8:56 AM

Post #1 of 6 (984 views)
How to print output to STDOUT Can't Post

Is there any way to print o/p to STDOUT even when i give print to some file?
Note: My code had multiple perl modules.


(This post was edited by naven8 on Apr 9, 2012, 9:09 AM)


FishMonger
Veteran / Moderator

Apr 9, 2012, 9:11 AM

Post #2 of 6 (979 views)
Re: [naven8] How to print output to STDOUT [In reply to] Can't Post

Your question is not very clear. Are you asking if a single print statement could send its output to multiple filehandles?

Check out these modules:
http://search.cpan.org/~salva/File-Tee-0.07/lib/File/Tee.pm
http://search.cpan.org/~gfuji/PerlIO-Util-0.72/lib/PerlIO/tee.pm
http://search.cpan.org/~kenshan/IO-Tee-0.64/Tee.pm


naven8
Novice

Apr 9, 2012, 9:18 AM

Post #3 of 6 (977 views)
Re: [FishMonger] How to print output to STDOUT [In reply to] Can't Post

Actually i have a perl code where there are multiple modules involved. I have used multiple file operation in the code so the o/p will be pre-processed before writing to a file. But i want to check the actual o/p before it got processed. For this i need a option which will force everything to stdout.


FishMonger
Veteran / Moderator

Apr 9, 2012, 9:28 AM

Post #4 of 6 (975 views)
Re: [naven8] How to print output to STDOUT [In reply to] Can't Post

I'm sorry, but I still can't make out what problem you're trying to resolve. The default filehandle that a print statement uses is STDOUT.

Please post your code and provide a clear explanation of what you need to accomplish.


naven8
Novice

Apr 9, 2012, 9:44 AM

Post #5 of 6 (971 views)
Re: [FishMonger] How to print output to STDOUT [In reply to] Can't Post

Posting some eg code:

Code
Merror.pm 
###########
sub error{
//This will process the errors. It will print only some messages in the o/p file. Some error will be filtered.
}
###########

runt.pm
###########
use Merror;
use base qw(Merror);

###########

Script.pl
###########
use runt;

my $obj= runt->new();


###########



In my code i called some function in runt.pm and it failed with some error. Due to this error we call "error" function in Merror module to process the error. Here my run is getting killed and there is no message printed to o/p because of some processing.

Is there any way to get the call-stack for this? or Force the o/p to stdout?
I have used Carp to get call-stack but the error function is pre-processing everything.Even that didn't help.
So i need a option which will force everything to o/p.
Note: Here i have shown only 3 files but my actual code involves multiple files.

Thanks


FishMonger
Veteran / Moderator

Apr 9, 2012, 12:02 PM

Post #6 of 6 (956 views)
Re: [naven8] How to print output to STDOUT [In reply to] Can't Post

The most important step when posting questions is to provide a clear and concise problem statement, which you have not done. However, I do get the basic gist of what you need.

You'll want to start by using the caller function to get the context of the current subroutine call.
http://perldoc.perl.org/functions/caller.html

If you're not already doing so, you'll want to add a Debug flag and base the level of debug output on the value of that flag.

The error output should go to STDERR, not STDOUT.

If you need low level stack trace info, then use one of the Devel modules, such as Devel::StackTrace or Devel:CallerStack.
http://search.cpan.org/~drolsky/Devel-StackTrace-1.27/lib/Devel/StackTrace.pm
http://search.cpan.org/~exodist/Devel-CallerStack-0.003/lib/Devel/CallerStack.pm
http://search.cpan.org/search?query=devel+stack&mode=all

You may want to use one of the Tee modules that I previously linked to so you can use a single print statement to output the debug data to multiple filehandles.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives