[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash, perl, C



On Sat, Jan 08, 2005 at 12:18:33AM +0100, Gerard Robin wrote:
> On Sat, Jan 08, 2005 at 10:32:57AM +1300, Andrew Walbran wrote:
> > On Sat, 08 Jan 2005 6:28 am, Gerard Robin wrote:
> > > Hello,
> > > can someone explain to me if it is possible that the functions sleep of C
> > > and Perl work like the function sleep of bashin this scripts and program:
> > 
> > 'man 1 sleep' explains what sleep does in bash; 'man 3 sleep' explains what 
> > sleep does in C.
> 
> I think that my question was not very clear.
> 
> timerest3.pl in fact is a subroutine in a little script Perl that I wrote 
> myself ( I am not a student who expect that others do his work :-))
> In that subroutine I wrote
> ......
> while ($i < 6) {
> print "\e[0;46;31m", 5-$i, "\e[0m";
> `sleep 1`; # the sleep of the shell
> print "\r";
> .......
> 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 ?
> 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 ...

I guess your problem is not with sleep, but with buffered output.
In the shell script, echo is a separate command, so its output is
immediately didplayed. In both perl and C, standard output is buffered
for efficiency reasons.
Try adding 
fflush(stdout);
to the C version after every printf line.
I don't know how to do this in perl, but I'm sure it is possible.

Frank



> 
> But I accept that my problem is irrelevant with the list debian-user.
> I apologise for having disturb you.
> 
> Thanks.
> 
> -- 
> G?rard 
>  
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

-- 
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan



Reply to: