title: How to enforce a definite timeout in perl?
body: <p>I am using LWP to download content from web pages, and I would like to limit the amount of time it waits for a page.</p>
  
  <pre><code>my $ua = LWP::UserAgent-&gt;new;
  $ua-&gt;timeout(10);
  $ua-&gt;env_proxy;
  $response = $ua-&gt;get("http://XML File");
  $content = $response-&gt;decoded_content;
  </code></pre>
  
  <p>The problem is that the server will occasionally deadlock (we're trying to figure out why) and the request will never succeed. Since the server thinks it is live, it keeps the socket connection open thus LWP::UserAgent's timeout value does us no good what-so-ever. What is the best way to enforce an absolute timeout on a request?</p>
  
  <p>Whenever the timeout reaches its limit, it just dies and I can't continue on with the script! 
  This whole script is in a loop, where it has to fetch XML files sequentially.
  I'd really like to handle this timeout properly and make the script continue to next address. Does anyone know how to do this? Thanks!!</p>