title: Parsing of Text File using Perl
body: <p>i have a text file which looks like this.</p>
  
  <pre><code>    Parameter 0:
      Field 1           : 100
      Field 2           : 0
      Field 3           : 4
  
      Parameter 1:
      Field 1           : 873
      Field 2           : 23
      Field 3           : 89
  </code></pre>
  
  <p>I want to write a perl script that parses this file in the following format</p>
  
  <pre><code>     Parameter Field1 Field2 Field3
         0          100     0      4
         1          873     23     89
  </code></pre>
  
  <p>Can anyone help me with this. Any help will be greatly appreciated.
  i have tried the following so far</p>
  
  <pre><code>my %hash = ();
  my $file = "sample.txt";
  
  open (my $fh, "&lt;", $file) or die "Can't open the file $file: ";
  
  while (my $line =&lt;$fh&gt;)
  {
      chomp ($line);
      my($key) = split(" : ", $line);
      $hash{$key} = 1;
  }
  
  foreach my $key (sort keys %hash)
  {
      print "$key\n";
  }
  </code></pre>