in reply to Re: sleep in infinite loop
in thread sleep in infinite loop

But how to print it to a file? Even after printing it, the file is of zero byte.

Replies are listed 'Best First'.
Re^3: sleep in infinite loop
by dasgar (Priest) on Aug 02, 2010 at 13:41 UTC

    Based on the code that you provided, you're not doing anything with any files. Your print statement is only printing to STDOUT (i.e. your monitor).

    Assuming that you want to print to both your screen and the file, the modifications to your code below should work.

    #!/usr/bin/perl use warnings; use strict; my $file = "file.txt"; open(OF,">",$file) || die "Unable to open file '$file': $!\n"; while (1) { sleep 5; print "interval\n"; # prints to screen print OF "interval\n"; # prints to file } close(OF);