title: Perl Curses::UI - Loops
body: <p>I'm new to Perl and Curses but I'm struggling to get my code to run a loop, to start with here's my code:</p>
  
  <pre><code>#!/usr/bin/env perl
  
  use strict;
  use Curses::UI;
  
  sub myProg {
      my $cui = new Curses::UI( -color_support =&gt; 1 );
  
      my $win = $cui-&gt;add(
          "win", "Window", 
          -border =&gt; 1, 
      );
  
      my $label = $win-&gt;add(
          'label', 'Label', 
          -width         =&gt; -1, 
          -paddingspaces =&gt; 1,
          -text          =&gt; 'Time:', 
      );
      $cui-&gt;set_binding( sub { exit(0); } , "\cC");
  
      # I want this to loop every second 
      $label-&gt;text("Random: " . int(rand(10)));
      sleep(1);
  
      $cui-&gt;mainloop();
  
  }
  
  myProg();
  </code></pre>
  
  <p>As you can see I want this section to run recursively:</p>
  
  <pre><code>    # I want this to loop every second 
      $label-&gt;text("Random: " . int(rand(10)));
      sleep(1);
  </code></pre>
  
  <p>The idea of putting a random number in a label is just to show it works, I will eventually have quite a few labels that will be changed regularly and would like to do other functions as well.</p>
  
  <p>I've tried doing:</p>
  
  <pre><code>while (1) {
      ...
  }
  </code></pre>
  
  <p>but if I do this before the mainloop(); call the window is never created and after the call it does nothing?</p>
  
  <p>Hope this makes sense? So how do I do it? </p>