title: Extraction and printing of key-value pair from a text file using Perl
body: <p>I have a text file temp.txt which contains entries like,</p>
  
  <pre><code>cinterim=3534
  cstart=517
  cstop=622
  ointerim=47
  ostart=19
  ostop=20
  </code></pre>
  
  <p>Note: key-value pairs may be arranged in new line or all at once in one line separated by space.</p>
  
  <p>I am trying to print and store these values in DB for corresponding keys using Perl.  But I am getting many errors and warnings.  Right now I am just trying to print those values.</p>
  
  <pre><code>use strict;
  use warnings;
  
  open(FILE,"/root/temp.txt") or die "Unable to open file:$!\n";
  
  while (my $line = &lt;FILE&gt;) {
    # optional whitespace, KEY, optional whitespace, required ':', 
    # optional whitespace, VALUE, required whitespace, required '.'
    $line =~ m/^\s*(\S+)\s*:\s*(.*)\s+\./;
    my @pairs = split(/\s+/,$line);
    my %hash = map { split(/=/, $_, 2) } @pairs;
  
    printf "%s,%s,%s\n", $hash{cinterim}, $hash{cstart}, $hash{cstop};
  
  }
  close(FILE);
  </code></pre>
  
  <p>Could somebody provide help to refine my program.</p>