in reply to sleep in infinite loop

You can add $| = 1 to turn on autoflush, then you'll see each "interval" as you print them.

Replies are listed 'Best First'.
Re^2: sleep in infinite loop
by Anonymous Monk on Aug 02, 2010 at 09:48 UTC
    But how to print it to a file? Even after printing it, the file is of zero byte.

      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);