LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2005, 10:27 AM   #1
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Rep: Reputation: 30
Perl timed actions?


I am relitivily new to perl and was wonding a good way to have something happen at timed intervals. For example every 5 or 10 seconds or something.

I am looking to check a value every 5 seconds and if the value has changed above or below the benchmarks set then certain actions are performed. But I am not sure how to have something happen over and over based on timed intervals.
 
Old 05-05-2005, 11:20 AM   #2
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
Code:
my $interval = 5;
$SIG{ALRM} = sub {
                  # Your code here...
                                
                  # Remember to restart the timer
                  alarm $interval;
                };
alarm $interval;
See "perldoc -f alarm" for details.

Last edited by Harmaa Kettu; 05-05-2005 at 01:49 PM.
 
Old 05-05-2005, 11:25 AM   #3
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
cool I will try this out as soon thank!!!!!!!!!!
 
Old 05-05-2005, 01:20 PM   #4
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
hmmmm I wrote my code and checked that it worked and everything compiled fine so I know my internal code is working, but when I put the code in between the timer code I get a error message

"syntax error at control.pl line 134, near "alarm"
Execution of control.pl aborted due to compilation errors."
 
Old 05-05-2005, 01:50 PM   #5
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
Sorry, some punctuation was missing from the code. Fixed now.
 
Old 05-05-2005, 02:09 PM   #6
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
Awsome it seemed to work perfect!!! Waited 5 seconds then the stuff changed based on current situation, of course i forgot code to change stuff back to the normal setting when the situation changes some stuff but I think YOUR code is working great!!!!!!!!!!!!!!!!!!!! thank you
 
Old 05-06-2005, 07:32 AM   #7
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
I have noticed one problem with this code!
If I am idle it will not check the code every 5 seconds!! If I move my mouse it will then start checking.

Anyone have any ideas how to correct this????????????



my $interval = 5;
$SIG{ALRM} = sub {
# Your code here...

# Remember to restart the timer
alarm $interval;
};
alarm $interval;
 
Old 05-06-2005, 07:34 AM   #8
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
Actually as I typed this I just watched it update, so I am not sure exactly what is going on, I guess sometimes it will update every 5 seconds and other times it wont!!!
Anyone got any ideas or insight to the problem they are appreaciated!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clam av actions branden_burger Linux - Security 1 07-31-2005 02:58 PM
Timed actions LongName Programming 2 09-02-2004 03:42 AM
rollback actions DriveMeCrazy AIX 6 05-16-2004 05:16 AM
how to do the following actions santasballz Linux - Newbie 8 02-20-2004 01:12 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration