in reply to Foreach time delay

The above works, but you are Suffering from Buffering.

Set autoflush if you want output to STDOUT to appear unbuffered:

$| = 1;

Alternatively, print newlines:

foreach (1..20) { print "a\n"; sleep (1);#between each element of the array there should be 1 sec +ond interval }

Replies are listed 'Best First'.
Re^2: Foreach time delay
by Anonymous Monk on Mar 16, 2017 at 10:55 UTC

    Thanks Corion, you opend a new world for me. Fantastic!

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Foreach time delay
by Anonymous Monk on Mar 16, 2017 at 15:14 UTC
    Is there any good reason why we're still line-buffering stdout? It seems like a throwback to the timesharing days. This is the 21st century, people!
      Yes there is:

      "If Perl made a system call for every read operation, that would be 10,001 system calls in all (one extra to detect end-of-file), and if the file was on the disk, it would have to wait for the disk at least 10,000 times. That would be very slow."

      Can you write a better OS?
        Oh, dear me. I assumed that you would know that stdout is line-buffered when it is going to a tty, and block-buffered when it isn't. The block-buffering is useful, it really speeds up pipes. The line-buffering is pretty much just a gotcha for newbies. Why do you want to speed up console output? It's just going to go scrolling by too fast for you to read.