title: How can I calculate values within pauses in an XML file using Perl
body: <p>I have an XML file with the following information:</p>
  
  <pre><code>&lt;Key Time="54288" Type="insert" Value="E" /&gt;
  &lt;Key Time="55288" Type="insert" Value="A" /&gt;
  &lt;Key Time="58298" Type="insert" Value="H" /&gt;
  &lt;Key Time="58398" Type="insert" Value="A" /&gt;
  &lt;Key Time="58498" Type="insert" Value="L" /&gt;
  &lt;Key Time="59298" Type="insert" Value="L" /&gt;    
  &lt;Key Time="64298" Type="insert" Value="O" /&gt;
  </code></pre>
  
  <p>I first need to calculate the total pause duration between each <code>Key</code> entry, but only when the pauses (the intervals since the previous <code>Time</code>) are equal to or higher than 2400.</p>
  
  <p>For that I got the script below, which also shows when the pause starts.</p>
  
  <pre><code>perl -nle '
     /&lt;Key +Time\s*=\s*"([0-9]+)\s*"/ and push @nums,$1; 
     END{ 
         for(1..$#nums){ 
             $pause=$nums[$_]-$nums[$_-1];
             $pause &gt;=2400 ? print "$pause started at ".$nums[$_-1] : ()
         }
     }' your_file_here &gt; output_file
  </code></pre>
  
  <p>This outputs</p>
  
  <pre><code>3010 started at 55288
  5000 started at 59298
  </code></pre>
  
  <p>However, now I need to improve the script to retrieve all values in between two >= 2400-long pauses, also including the value where the pause starts. For instance, from <code>Time="54288"</code> to <code>Time="55288"</code> I have <code>EA</code>; from <code>Time="58298"</code> to <code>Time="59298"</code> I have <code>HALL</code> etc.</p>