Path: utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: (f)flush? Message-ID: <8992@jpl-devvax.JPL.NASA.GOV> Date: 3 Aug 90 16:42:05 GMT References: <7193@star.cs.vu.nl> <8936@jpl-devvax.JPL.NASA.GOV> <1990Aug2.225410.2587@NCoast.ORG> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 47 In article <1990Aug2.225410.2587@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes: : I would like to have a per-filehandle immediate-flush flag to replace the : current $| variable. There are times when I want buffered output on one : filehandle but not the others. Er, we seem to laboring under a slight misapprehension here. The $| variable already IS a per-filehandle immediate-flush flag. The actual flag is stored out in the I/O structure--look at IOF_FLUSH in stab.h. When you refer to the $| varialbe, it's referring to that flag for the currently selected output filehandle, and not to the flag for any other filehandle. : Additionally, I'd like a "setbuf" function, again per-filehandle. : : Reason? I sat down and wrote a cpio in Perl in response to the tar in Perl : that was posted a few weeks ago, including a library to do tape buffering... : and then remembered that Perl uses stdio and its default buffers. I can turn : off buffering with $|, but it then goes character at a time instead of print : statement at a time, no? Depends on your implementation of STDIO, and what kind of thing you're writing to. Turning off $| merely makes it not do flushes. If it was unbuffered before, having $| on doesn't help you, and if it was buffered before, turning $| off won't make stdio unbuffered. On most systems, output to (raw) tape and disks is buffered. : And I don't necessarily want to unbuffer stdout : while I'm doing this, and setting $| every time I want to do tape I/O is a : major pain. Worse is to have a setbuf and have it apply to all filehandles : via $|; the standard tape block size on our machine is 512K bytes.... $| is not a global, and it has nothing to do with setbuf. : This buffering problem is the reason I haven't tried to post my cpio library; : as is, it has a lot of excess baggage via the nonfunctional tape-buffering : routines, and it won't write tapes with compatible block sizes. Worse, the : cpio-reading part will break on machines with stupid tape drivers which deal : with reading a small chunk of a large block (i.e. stdio-buffered read of a : 20-blocked cpio tape) by returning the requested amount of data and discarding : the rest of the block. And yes, there are machines which do that! : Mercifully, I've forgotten which one it was, but it screwed me up for a while : back when I was free-lance consulting. On machines with syscall(), you can get around dumb stdio limitations using it. It might be worthwhile for me to add a sysread() and syswrite() builtin to bypass stdio. Larry