Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to console and a file handle

Status
Not open for further replies.

denisl

Technical User
Jun 18, 2001
36
US
How can I have a print command send output to a file handle for logging and to the console?
 
Log::Log4perl might be one way way to do it.
Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I'm only whant to send to the logfile what I print to the console.. Not debug info..

In ksh I do:
Code:
echo "information" | tee -a logfile
 
Code:
open(FH, ">>" ,"logfile") or die "$!";
print FH "text\n";
print "text\n";
close FH;




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kevin - that would mean I have to issue a 2 prints, 1 for logfile and one for console.. Nothing more efficient?
 
There might be a way to define your own subroutine to replace "print", but in my experience in trying this, calling just one print from your code ends up getting into deep recursion.

-------------
Cuvou.com | The NEW Kirsle.net
 
I really doubt there is any loss of efficiency. Plus I don't know of any other way to do it.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top