title: Keep a perl script running
body: <p>I have a perl script that subscribes to a message queue using AnyEvent::MQTT.</p>
  
  <p>At the minute all I want it to do is print out when it get's a message. I'm totally new to perl so I'm using the demo code it comes with which includes a bit that publishes anything on the STDIN as a message - this works great, and I can see all the messages received.</p>
  
  <p>This code looks as follows</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  
  use AnyEvent::MQTT;
  my $mqtt = AnyEvent::MQTT-&gt;new;
  my $cv = $mqtt-&gt;subscribe(topic =&gt; '/AlarmMode',
                             callback =&gt; sub {
                                 my ($topic, $message) = @_;
                                         print $topic, ' ', $message, "\n"
                                     });
  
  my $qos = $cv-&gt;recv; # subscribed, negotiated QoS == $qos
  
  
  
    # publish line-by-line from file handle
        $cv =  $mqtt-&gt;publish(handle =&gt; \*STDIN,
                              topic =&gt; '/topic');
  </code></pre>
  
  <p>The issue I have is that if I remove everything after the comment <code>publish line-by-line from file handle</code> then my app exits as soon as it's ran.</p>
  
  <p>I've tried including a while loop that sleeps for 5 seconds but that does't work (the app just looks like it's hung).</p>
  
  <p>I know I need to do <em>something</em> to tell the app just to stay alive and chill, but I don't know what that command is :-)</p>