Re: Switching io redirection between display and file

2007-04-26 Thread Mumia W.

On 04/26/2007 07:05 AM, Nath, Alok (STSD) wrote:

Hi ,
Can somebody help me out ?

	I wanted to switch io redirection between log file and 
	standard display device.Basically sometimes I want to

print into a log file and other time to the display device.
[...]


"perldoc -f open" describes the technique.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Switching io redirection between display and file

2007-04-26 Thread Jeff Pang

2007/4/26, Nath, Alok (STSD) <[EMAIL PROTECTED]>:

Hi ,
   Can somebody help me out ?

   I wanted to switch io redirection between log file and
   standard display device.Basically sometimes I want to
   print into a log file and other time to the display device.

   To redirect I am using this

   open (STDOUT, ">> TEST.log)

   Two doubts here -
   1. I don't know how to reset it to default i.e to point STDOUT
to display again.
   2. Is there any better way of doing above ?



Hi,

Using "select" to do this thing is maybe better.

open FILE,">>",$logfile or die $!;
my $old = select FILE;
print "some things...";  # print to logfile
select $old;  # select back to STDOUT
print "other things..."; # print to STDOUT


--
Chinese Practical Mod_perl book online
http://home.arcor.de/jeffpang/mod_perl/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/