alarm - Perl: eval timer in while -


i try achieve timer several loops below

while ( $try < 3) {     eval {         local $sig{alrm} = {};         alarm 3;         $ret = # sending request , wait response         alarm 0;     }     last if defined($ret);     $try++; } 

but actually, when alarm expired, whole 'while' loop got interrupted, , loop didn't happen @ all.

where got thing wrong?

you need set alrm handler, alarm docs demonstrate:

for (1..3) {         print "loop $_\n";      eval {         local $sig{alrm} = sub { die "alarm\n" };         alarm 5;          $count = int rand 10;         print "is $count < 5?\n";          sleep $count;          alarm 0; #cancel alarm if not hang     };      if ($@) {         die unless $@ eq "alarm\n";   # propagate unexpected errors     } else {         print "our code succeeded\n";         last;     } } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -