in reply to how do I write directly to a file
Perl uses buffering on its filehandles; data is cached and written in 4K chunks. To turn that off, set the file handle to auto flush;
use IO::Socket; @colors = qw(pink yellow blue green); open(COLORS, ">>colors.txt") or die $!; # turn off stdio buffering on COLORS COLORS->autoflush(1); foreach $color (@colors){ print COLORS "$color\n"; print "sending $color to File\n"; } while (<STDIN>) { chomp; exit if ($_ eq "quit"); print COLORS $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: how do I write directly to a file
by davorg (Chancellor) on Jun 07, 2001 at 19:37 UTC |