print isn't flashed using PERL by MSWin32 on Windows XP

R

reyal

Hi,
I am using on WindowsXP home edition, PERL edition identified as
"v5.8.6 built for MSWin32-x86-multi-thread".

When using the print command, it doesn't flash the output string if
there is no "\n" at the end of the string.

Is this configurable or do I have to live with it?

Thanks,
Eyal
 
R

reyal

Sorry to bother again, but it doesn't work. And when looking again in
this group I found this problem already reported some 9 years ago:

************************************************************

Tungning Cherng Sep 9 1996, 12:00 am show options

Newsgroups: comp.lang.perl.misc
From: (e-mail address removed) (Tungning Cherng ) - Find messages by this
author
Date: 1996/09/09
Subject: flush stdout with eof
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

The following script
- without 'if (eof)' statement, the output will show up when I type the
input
right away (which as I expect.)
- with 'eof' (as the script), the output will delay. The first line
input
won't show up until the second line input is entered
(which I don't understand.)

I thought I put "select(STDOUT); $|=1;" to flush out the output. But
it
does not work.

#!/usr/local/bin/perl
select(STDOUT); $|=1;
while (<STDIN>)
{
print "before \n";
if (eof)
{
print "lastline-> $_";
last;
}
print "output-> $_";
}


The output looks like:
first line
before
second line
output-> first line
before
lastline-> second line (I typed ^D to eof)

Can someone explain?

Thanks,
Donnie


*******************************************************************************
I'm not sure that they originate from the same problem, but still I
don't have a solution. For now I simply add "\n"s.

Thanks anyway,
Eyal
 
A

A. Sinan Unur

Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP

'flash' and 'flush' are two different things. ITYM 'flush'.

Not PERL, Perl.
Sorry to bother again, but it doesn't work.

What doesn't work? Please quote an appropriate amount of context when
you are responding. Please read the posting guidelines posted here
regularly.
And when looking again in this group I found this problem already
reported some 9 years ago:

************************************************************

Tungning Cherng Sep 9 1996, 12:00 am show options

There is no point in cutting and pasting from Google like this. What if
I wanted to check other messages in that thread? It would have been far
more useful to use the message ID to refer to the message.
I'm not sure that they originate from the same problem, but
still I don't have a solution. For now I simply add "\n"s.

Maybe I am very easily confused, but this got me curious so I decided to
test is myself. Here is the code:

#! /usr/bin/perl

use strict;
use warnings;

$| = 1;

while(<STDIN>) {
print "$. << ";
if (eof) {
print "lastline: $_";
} else {
print "entered: $_";
}
}

__END__

Notice that I am not chomp'ing $_ after input. So, I would expect to see
the following when I run this script:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << entered : one
two
2 << entered : two
....

In fact, I would have expected this output even without setting
autoflush on. Instead, what get is:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << two
entered : one
2 << three
entered : two
3 <<
....

If I change the code to:

#! /usr/bin/perl

use strict;
use warnings;

my $t = time;

while(<STDIN>) {
print "$. << ";
if ($t > time) {
print "lastline : $_";
} else {
print "entered : $_";
}
}

__END__

I get:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << entered : one
two
2 << entered : two
....

So, the culprit seems to be the call to eof.

Now, the documentation of eof does indeed state that it is not very
useful in an interactive setting, and I do not think I have a line of
code anywhere with a call to eof in it (be it C, Java or Perl). Granting
that, I am still a little confused about this behavior.

Sinan.
 
A

Anno Siegel

A. Sinan Unur said:

[eof() with a terminal]
So, the culprit seems to be the call to eof.

Now, the documentation of eof does indeed state that it is not very
useful in an interactive setting, and I do not think I have a line of
code anywhere with a call to eof in it (be it C, Java or Perl). Granting
that, I am still a little confused about this behavior.

It appears to be consistent with the fact that eof() hangs until a
character of input is available. It doesn't consume a character,
but since on a terminal the eof condition is represented as a character
it must look at one, so wait for one.

Anno
 
A

A. Sinan Unur

(e-mail address removed)-berlin.de (Anno Siegel) wrote in
A. Sinan Unur said:

[eof() with a terminal] ....
It appears to be consistent with the fact that eof() hangs until a
character of input is available. It doesn't consume a character,
but since on a terminal the eof condition is represented as a
character it must look at one, so wait for one.

Ah, it's so obvious when you put it that way! Thanks :)

Sinan.
 
G

GreenLeaf

reyal said:
Sorry to bother again, but it doesn't work.

Give examples (preferably the minimal code that reproduces the error) on
when or where it does not work. Your example from someone else's post is
a different matter that has nothing to do with flushing. Flushing issue
is not even applicable there because (among other things) the input line
you get from <STDIN> comes with a "\n", so a simple print would flush it
with or without autoflushing on.

Apparently the OP of the post you extracted was aware that the problem
was with the call to eof. Sinan and Anno clearly explained what happens
there. On your problem, the following code works for me as expected.
That is, if autoflush is set to 0, it waits 5 seconds to flush the
whole line.

Cheers :eek:),
sat


#! /usr/bin/perl
use strict;
use warnings;

print 'Enter autoflush value : ';
$_ = <>;
chomp;
$| = $_;

for (1..20) {
print time;
print "\n" unless ($_ % 5);
sleep(1);
}

__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top