You may have to use syswrite instead of print to get around the
buffering. Syswrite can be a pain though.....
#!/usr/bin/perl
$x = "hello world ";
$l = length $x;
while () {
syswrite STDOUT, $x, $l;
sleep 1;
}
And, according to the book, "do not mix calls to (print or write) and
syswrite on the same filehandle unless you are into heavy wizardry."
Dan wrote:
>
> Here's one that's driving me mad ... I'm trying to write a script and I want
> the output to continue on the same line, but when I add in anything that
> slows down the loop I can only get an output if I add a line feed.
>
> (RH 6.1 and perl-5.00503-6.)
>
> Any ideas?
>
> Dan.
>
> Three example are below to try and explain what I mean.
>
> -----------------------------------------------------------------------------
>
> #!/usr/bin/perl
>
> while () {
> print "hello world";
> }
>
> gives
>
> o worldhello worldhello worldhello worldhello worldhello worldhello
> worldhello worldhello worldhello worldhello worldhello worldhello worldhello
> worldhello worldhello worldhello worldhello worldhello worldhello worldhello
> worldhello worldhello worldhello worldhello worldhello wor
>
> ------------------------------------------------------------------------------
>
> When I add something in that slows the loop down, a subroutine, or even a
> simple sleep command ...
>
> #!/usr/bin/perl
>
> while () {
> print "hello world";
> sleep 1;
> }
>
> I get nothing at all, the cursor just sits there.
>
> ------------------------------------------------------------------------------
>
> Then I add a line feed ...
>
> #!/usr/bin/perl
>
> while () {
> print "hello world\n";
> sleep 1;
> }
>
> And get this ...
>
> hello world
> hello world
> hello world
> hello world
> hello world
> hello world
> hello world
> hello world
>
--
Regards,
Jim Reimer - WA5RRH
[EMAIL PROTECTED]
http://www.webzone.net/jdreimer
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs