Metronome: Difference between revisions
Content added Content deleted
(→{{header|Perl}}: code fixes and enabled autoflush) |
|||
Line 759: | Line 759: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
The module <code>Time::HiRes</code> provides sub-second <tt>sleep</tt>. Text output only. |
The module <code>Time::HiRes</code> provides sub-second <tt>sleep</tt>. Text output only. |
||
<lang perl>use Time::HiRes qw(sleep); |
<lang perl>use Time::HiRes qw(sleep gettimeofday); |
||
local $| = 1; # autoflush |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
my $i = 0; |
|||
while () { |
|||
⚫ | |||
⚫ | |||
my $base_time = gettimeofday() + $duration; |
|||
for (my $next_time = $base_time ; ; $next_time += $duration) { |
|||
⚫ | |||
print "\nTICK"; |
print "\nTICK"; |
||
} |
} |
||
else { |
|||
print " tick"; |
print " tick"; |
||
} |
} |
||
sleep |
sleep($next_time - gettimeofday()); |
||
}</lang> |
}</lang> |
||
Sample run |
Sample run |