Re: bash, perl, C
On Sat, 8 Jan 2005 00:18:33 +0100, Gerard Robin <firstname.lastname@example.org> wrote:
> If i use the sleep of Perl there nothing is displayed at though with the sleep
> of the shell the numbers 5 4 3 2 1 0 are displayed as I want.
> And, I don't understand why the sleep of Perl doesn't work ?
The sleep function works, but the output that has been outputted with
print has not been flushed. To make Perl automatically flush after
every print statement, put this line in your script:
$| = 1;
This enables the OUTPUT_AUTOFLUSH. You only need to do this once in
the script. The name of the variable is just a pipe. Once you do this,
the script works just as it did with the shell's sleep.
> I think it is not coherent to use the sleep of the shell whereas Perl has such
> function. And I tried to write this function in C to rewrite my program in
> C ..... but the C function sleep in C works like in Perl ...
Same thing with C. To make it flush, call fflush(0) after each time
you call printf.