Away from PC so I cannot hookup Is alarm perls internal function? -----Original Message----- From: "Chas. Owens" <chas.ow...@gmail.com>
Date: Wed, 1 Apr 2009 10:18:51 To: Kelly Jones<kelly.terry.jo...@gmail.com> Cc: <beginners@perl.org> Subject: Re: Calling subroutine every second using alarm fails On Wed, Apr 1, 2009 at 08:48, Kelly Jones <kelly.terry.jo...@gmail.com> wrote: > I want a script that constantly accepts user input, but runs a > subroutine every second to do other work. My attempt: > > $|=1; $SIG{'ALRM'}= "\&alarm_sub"; &alarm_sub; > while (<>) {print "You typed: $_\n";} > sub alarm_sub {print "ALARM!\n"; alarm 1; return;} > > fails miserably. What's the right way to do this? snip You are never setting the first alarm. Also, since you are planning on sharing variables with the handler, it is probably better to use a closure than a function: #!/usr/bin/perl use strict; use warnings; my $wait = 1; local $SIG{ALRM} = sub { print "in alarm\n"; alarm $wait; }; alarm $wait; while (my $line = <>) { print "You said: $line\n"; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/