in reply to Any ideas for using perl as a simple pulse generator?
No need to use two threads.
use IO::Handle qw( ); use Time::HiRes qw( time sleep ); open(my $fh, '>', $file) or die; $fh->autoflush(1); my $target = time() + 0.500; for (;;) { print($fh "1"); $target += 0.500; sleep($target - time()); }
If your program needs to do something else at the same time, you can use a dedicated process (fork) or thread (async{ ... }->detach();).
Notes:
Update: Fixed bug identified in reply. Moved autoflush out of the loop.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Any ideas for using perl as a simple pulse generator?
by almut (Canon) on Jul 13, 2010 at 21:44 UTC | |
|
Re^2: Any ideas for using perl as a simple pulse generator?
by bfreemer (Novice) on Jul 13, 2010 at 21:38 UTC |