Mike wrote: > I'm using perl 5.10 with Tkx and am trying to implement an interval > timer on my Win32 (XP) box. After reading the documentation, I'm only > attempting to use the ITIMER_REAL because I'm on a Win32 platform. > > my "dumbed down" code: > > use Time::HiRes qw( setitimer ITIMER_REAL ); > $SIG{ALRM} = sub { print time, "\n" }; > setitimer(ITIMER_REAL, 10, 2.5);
Windoze doesn't have a signal mechanism, so alarms don't really work and itimers aren't implemented. You can use the alarm function (seconds resolution) if you're not doing anything that will block your code because it's faked in Perl. What specifically are you using it for and what resolution do you need ? You can use Win32::GetTickCount to get more accurate timing, but it's not an alarm - just a timer. Here's some sample code to illustrate alarm and GetTickCount: use strict; use warnings; my $x = 0; my $pt0 = Win32::GetTickCount (); eval { $SIG{ALRM} = sub { die "5 second alarm went off\n" }; alarm 5; while (1) { # if you should block on an IO in here, you're stuck $x += 1; print "x=$x\n"; sleep 1; } alarm 0; }; if ($@) { my $diff = Win32::GetTickCount () - $pt0; printf "Actual time = %.3f sec\n", $diff / 1000; print "Timed out at ($x)\n$@"; die "eval timeout\n" if $@ =~ /5 second alarm went off/i; } else { print "Didn't timeout ($x)\n"; } _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs