title: How can I test STDIN without blocking in Perl?
body: <p>I'm writing my first Perl app -- an AOL Instant Messenger bot that talks to an Arduino microcontroller, which in turn controls a servo that will push the power button on our sysadmin's server, which freezes randomly every 28 hours or so. </p>
  
  <p>I've gotten all the hard stuff done, I'm just trying to add one last bit of code to break the main loop and log out of AIM when the user types 'quit'.</p>
  
  <p>The problem is, if I try to read from STDIN in the main program loop, it blocks the process until input is entered, essentially rendering the bot inactive. I've tried testing for EOF before reading, but no dice... EOF just always returns false.</p>
  
  <p>Here's below is some sample code I'm working with:</p>
  
  <pre><code>while(1) {
      $oscar-&gt;do_one_loop();
  
  # Poll to see if any arduino data is coming in over serial port
      my $char = $port-&gt;lookfor();
  
  # If we get data from arduino, then print it
      if ($char) {
          print "" . $char ;
      }
  
      # reading STDIN blocks until input is received... AAARG!
      my $a = &lt;STDIN&gt;;
      print $a;
      if($a eq "exit" || $a eq "quit" || $a eq 'c' || $a eq 'q') {last;}
  }
  
  print "Signing off... ";
  
  $oscar-&gt;signoff();
  print "Done\n";
  print "Closing serial port... ";
  $port-&gt;close() || warn "close failed";
  print "Done\n";
  </code></pre>