title: Perl EV module create periodic events
body: <p>I'm using EV module to create a timed events that will run indefinitely in a defined time interval, here is my code with defined intervals. </p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings qw/ all FATAL /;
  use feature 'say';
  use EV;
  use Time::Piece 'localtime';
  
  my $one_sec = EV::timer 1,1, sub {
     say "(1s)  Periodic event at ", localtime(EV::now)-&gt;hms;
  };
  
  my $five_sec = EV::timer 5, 5, sub {
    say "(5s)  Periodic event at ", localtime(EV::now)-&gt;hms;
  };
  
  EV::run;
  </code></pre>
  
  <p>I'm trying to define these functions dynamically from hash reference, by looping through it to create these functions.</p>
  
  <pre><code>my $hash = {
      'one_sec'  =&gt; '1',
      'five_sec' =&gt; '5',
  };
  </code></pre>
  
  <p>I have used foreach to loop through the hash.</p>
  
  <pre><code>foreach my $key ( keys %$hash )
  {
  
          my $key = EV::timer $hash-&gt;{$key},$hash-&gt;{$key}, sub {
          say "($hash-&gt;{$key})  Periodic event at ", localtime(EV::now)-&gt;hms;
          };
  
          EV::run;      
  }
  </code></pre>
  
  <p>It works, but only for the first iteration, I'm not sure why is that? </p>
  
  <p>Your thoughts are highly appreciated.  </p>