in reply to Re: Arrays of Hashes
in thread Arrays of Hashes

I was skimming past this, thinking: it's the sleep that's delaying things. Then I read:

Try either adding a newline at the end of the print

which I don't understand. I tested it, and of course it works, but... why does adding a newline cause the print statement to be released before the sleep? Then, it made me think: why on earth is the *subsequent* sleep delaying an earlier print? Can anyone explain this to ignorant monk?

Replies are listed 'Best First'.
Re: Re: Re: Arrays of Hashes
by jasonk (Parson) on Sep 23, 2003 at 19:35 UTC

    The result is getting buffered, in case you print more output which should be appended to the end of the line you already have, adding the newline tells the system that you are definately not going to be adding new information to the end of that line, so it doesn't have to buffer it anymore. I'm assuming you are running this in some manner that causes a window to pop up and display the output and then disappears when the program is finished, which would explain the sleep. If you run it from the command line you would see that the buffer also gets flushed when the program exits, so you would get your output eventually, just not until the sleep was finished.


    We're not surrounded, we're in a target-rich environment!
Buffered Output
by DentArthurDent (Monk) on Sep 23, 2003 at 19:46 UTC
    The issue is that Perl, like most other programming languages buffers screen output by default then outputs it all at once under certain circumstances. Those circumstances in Perl are either printing out a newline character, or manually flushing out the buffer. There may be others, I'm but a novice. Anybody know other ways?

    Hope that helps!
    Ben