title: How do I use sprintf to zero fill to a variable length in Perl?
body: <p>I want to use Perl's <a href="http://perldoc.perl.org/functions/sprintf.html" rel="noreferrer">sprintf</a> to zerofill a variable.</p>
  
  <pre><code>sprintf("%08d", $var);
  </code></pre>
  
  <p>But I want to dynamically determine how many digits to zerofill.</p>
  
  <p>How do I replace the "8" in <code>sprintf("%08d", $var)</code> with a variable called <code>$zerofill</code>?</p>