Perl Multiple Subroutines -


it may simple question perl expert -

i trying run script should logically this>

main {  while (true)   call sub   call sub b   call sub c }  sub { go execute method whatever needs --- before next time method runs need wait atleast 60 seconds still want call method b in these 60 seconds. }  sub b {   go execute method b whatever needs --- before next time method b runs need wait atleast 60 seconds still want call method c in these 60 seconds in mean time.  }  sub c {   go execute method c whatever needs --- before next time method c runs need wait atleast 60 seconds @ moment control should in main , wait first 60 seconds of expire sub can called } 

my question: q: best , optimized way can -?

q: if put sleep 60 in each sub next sub not called till 60 seconds expire , delay overall processing.

q: want 3 subs called every 60 seconds in sequential order

q lastly if need call 2 subs in every 60 seconds , last sub every hour - how do it?

comment - thought take utc variable , store in variable , keep checking time if time expires call individual subs not sure if optimum way of running code.

you want use threads. following snippet might give starting point. since have 4 qs instead of one, won't go detail each of them.

#!/usr/bin/perl  use warnings; use strict; use threads;  @t = (   threads->create(\&a),   threads->create(\&b),   threads->create(\&c) );  $t[0] -> join(); $t[1] -> join(); $t[2] -> join();  sub {   $i (1 .. 10) {      print "a $i\n";      sleep 60;   } }  sub b {   $i (1 .. 20) {      print "b $i\n";      sleep 60;   } }  sub c {   $i (1 .. 3) {      print "c $i\n";      sleep 60;   } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -