title: How can I include a variable in a Perl printf expression?
body: <p>How can I include a variable in a printf expression?</p>
  
  <p>Here's my example:</p>
  
  <pre><code>printf "%${cols}s", $_;
  </code></pre>
  
  <p>Where <code>$cols</code> is the number of columns
  and <code>$_</code> is a string.</p>
  
  <p>The statement results in an "Invalid conversion" warning.</p>
  
  <p>The problem ended up being that I forgot to chomp the variable. Gah. Thanks everyone.</p>