Trent Rigsbee wrote:
>
> I'm sure this is easy but I'm a newbie. I was doing control statements (for,
> while,etc.) like this:
>
> for ($count = 1; $count <= 5; $count++) {
> print "$count\n";
> }
In Perl that is usually written as:
for $count ( 1 .. 5 ) {
print "$count\n";
}
> What I wanted to do was to make each number appear in sequence like you see
> in a countdown (or up, in this case) instead of all on the screen at once.
In most consoles/terminals standard output (STDOUT) is line buffered.
man 3 stdout
[snip]
The stream stderr is unbuffered. The stream stdout is line-buffered
when
it points to a terminal. Partial lines will not appear until
fflush(3) or
exit(3) is called, or a newline is printed. This can produce
unexpected
results, especially with debugging output.
man 3 setbuf
[snip]
The three types of buffering available are unbuffered,
block buffered, and line buffered. When an output stream
is unbuffered, information appears on the destination file
or terminal as soon as written; when it is block buffered
many characters are saved up and written as a block; when
it is line buffered characters are saved up until a new�
line is output or input is read from any stream attached
to a terminal device (typically stdin).
Since you are printing a newline after $count the value of $count should
appear on your screen as soon as it is available. You can force STDOUT
to automatically flush its buffer by setting the autoflush variable to a
non-zero value before using STDOUT.
$| = 1; # turn on autoflush
for $count ( 1 .. 5 ) {
print "$count\n";
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]