Janek Schleicher wrote:
> Rob Dixon wrote at Sat, 29 Mar 2003 12:59:22 +0000:
>
> >     use IO::Handle;
> >     autoflush STDOUT;
> >     autoflush STDERR;
> >
> >     print STDERR "STDERR\n";
> >     print STDOUT "STDOUT\n";
> >
> > so that the output you see is in the order it happens. Without the
> > autoflush calls ( or even with just $| = 1 ) the above program will
> > output
> >
> >     STDOUT
> >     STDERR
>
> The following snippet:
> #!/usr/bin/perl
>
> $| = 1;
> print STDERR "STDERR\n";
> print STDOUT "STDOUT\n";
>
> $| = 0;
> print STDERR "STDERR\n";
> print STDOUT "STDOUT\n";
>
> has the output
>
> STDERR
> STDOUT
> STDERR
> STDOUT
>
> and not
> STDOUT
> STDERR
> ...

Hi Janek.

perldoc perlvar:

    [$|'s] default is 0 (regardless of whether the channel is really
    buffered by the system or not; "$|" tells you only whether you've
    asked Perl explicitly to flush after each write).

In this case it looks like your system may flush the buffers anyway,
this code:

    $| = 1;
    print STDERR "STDERR\n";
    print STDOUT "STDOUT\n";

sets autoflush only on STDOUT and then prints to both filehandles.
If STDERR were buffered then 'STDOUT' would be flushed first
and appear as the first line. If you disable autoflush altogether
then the result depends on which stream the system flushes for
you first. Try reversing the 'print' statements in your program
to see if it still prints STDERR first without any autoflush setting.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to