[VPM] I'm just full of questions today

Peter Scott peter at PSDT.com
Tue Mar 18 15:22:44 CST 2003


At 01:09 PM 3/18/03 -0800, nkuipers wrote:
>Hello again,
>
>I've re-reading the Llama, just to come back to basics a bit and consolidate,
>and I came across the following in Chapter 11, page 150 (the first footnote):
>
>"Also, generally, errors aren't buffered.  That means that if the standard
>error and standard output streams are both going to the same place (such as
>the monitor), the errors may appear earlier than the normal output.  For
>example, if your program prints a line of ordinary text, then tries to divide
>by zero, the output may show the message about dividing by zero first, 
>and the
>ordinary text second."
>
>Let's break that down.
>
>-generally, errors aren't buffered

s/generally/almost always/

>When are they buffered, how do you recognize when this is the case,

Never wanted/had to.

>and how do
>you apply error buffering (and why/when would you want to)?

my $oldfh = select STDERR;
$| = 0;
select $oldfh;

You'd need a darn good reason.  There's been a thread recently on 
clpmod about intercepting stderr and stdout and keeping the streams in 
the same order that you'd see them on the terminal (where stdout is 
line buffered instead of fully buffered).  If you had the source of the 
application being run perhaps you could handle this by buffering 
stderr.  But I'm stretching here.

>-the output may show the message about dividing by zero first, and the
>ordinary text second
>
>May?  As in, this is a platform-dependent phenomenon?

Yes.

>This is a magical phenomenon?

No.

>This is perl taking a guess and generally being wrong phenomenon?

Nothing to do with Perl, it's to do with how terminal drivers and 
shells set buffering on their I/O streams.  The same problem is faced 
by any language and on most if not all operating systems.

>  Also, this behavior seems awfully reminiscent of a stack.  Is there 
> a stack under the hood here?

No.

>too much to know...

Don't worry about this.  It's highly unlikely to cause you any issues, 
and if it ever does, you'll know about it when it happens.

If you really want to know the ugly truth, read Steven's Advanced 
Programming in the Unix Environment.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/




More information about the Victoria-pm mailing list