title: perl print formatting question
body: <p>I want to display a table in perl, the rows and column names for which will be of variable length. I want the columns to be neatly aligned. The problem is the row and column heading are of variable length, so the alignment shifts off for different files.</p>
  
  <p>Here is the code I am using to format :</p>
  
  <pre><code>print "\n              ";
  foreach (keys(%senseToSenseCountHash))
  {
   printf "%15s",$_;
  }
  print "\n";
  print "------------------------------------------------------------\n";
  
  my $space = "---";
  
  foreach my $realSense (keys(%actualSenseToWronglyDisambiguatedSense))
  { 
   printf "%s",$realSense; 
  
          foreach (keys(%senseToSenseCountHash))
   {
     if(exists($actualSenseToWronglyDisambiguatedSense{$realSense}[0]{$_}))
     {
    printf "%15s",$actualSenseToWronglyDisambiguatedSense{$realSense}[0]{$_};
     }
     else
     {
    printf "%15s",$space;
     }
   }
   print "\n";
  }
  </code></pre>
  
  <p>The outputs I get are as follows (for different files that I have to test on) :</p>
  
  <pre><code>                    Microsoft            IBM
  ------------------------------------------------------------
  Microsoft            896            120
  IBM             66            661
  
  
  
                       SERVE12         SERVE2         SERVE6        SERVE10
  ------------------------------------------------------------
  SERVE12            319             32             19              8
  SERVE2             44            159             39             25
  SERVE6             22              9            102              1
  SERVE10             14             16             12            494
  
  
  
                         HARD3          HARD2          HARD1
  ------------------------------------------------------------
  HARD3             68              7             27
  HARD2              6             60             90
  HARD1             37             69            937
  </code></pre>
  
  <p>I want to make this output aligned regardless of the row and column name. Can anyone please help? </p>
  
  <p>Thanks so much!</p>