nwkcmk has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks,

Currently have problem trying to print a single dot on the screen continuously whenever a subroutine is called but it looks like I can only see those dots when an escape sequence "\n" is placed in the print function or when the script ended.

For example, I wanted to output a dot on the screen every second for 5 seconds but can only see them after 5 seconds.

@time = (1..5); foreach (@time) { print "."; sleep 1; }

Replies are listed 'Best First'.
Re: printing without escape sequences "n"
by davido (Cardinal) on Feb 03, 2005 at 02:19 UTC

    Modify your code as follows:

    @time = ( 1 .. 5 ); { local $| = 1; # Set buffering to autoflush. foreach ( @time ) { print "."; sleep 1; } }

    See perlvar under the $| description for an explanation of the buffering autoflush special variable.


    Dave

Re: printing without escape sequences "n"
by data64 (Chaplain) on Feb 03, 2005 at 05:53 UTC