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 $_; }
In reply to Re: how do I write directly to a file
by mugwumpjism
in thread how do I write directly to a file
by Fathersuperior
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |