in reply to Re: writing to logfile in a loop
in thread writing to logfile in a loop
That's needlessly complicated. LOG and $io? autoflush and other IO::Handle methods can be used on any file handle, including barewords. That means that only LOG is needed. Or better yet, a lexical var ($log).
use strict; use warnings; use IO::Handle; my $log_file = 'mylogfile.txt'; open my $log, '>>', $log_file or die "Unable to open log file \"$log_file\": $!\n"; STDOUT->autoflush(1); $log->autoflush(1); my $foo=0; while(1){ $foo++; printf "Iteration: %d\n",$foo; $log->printf("Looped in %d\n",$foo); # or printf $log ... sleep 2; }
I also
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: writing to logfile in a loop
by blue_cowdawg (Monsignor) on Nov 21, 2006 at 22:26 UTC | |
by ikegami (Patriarch) on Nov 21, 2006 at 23:28 UTC |