Sprintf in Perl doesn't display hexadecimal character properly
<p>I have a code like this.</p>

<pre><code>     $entry = &amp;function();   //returns a number between 0 to 20
     $var = sprintf("%#.4x", $entry);
     if($var=~ /$hex/)
     {
         //block of statements
      }
</code></pre>

<p>$hex will be within 0x0000 ..... 0x0014. Now, when <code>function</code> returns from 1 to 20, $var matches $hex. (Like 0x0001 .... 0x0014)</p>

<p>But when $entry is 0, $var becomes <code>0000</code>. But I want it to be <code>0x0000</code>. Currently, I am checking if that is <code>0000</code>, I am changing it through a if loop. Please let me know if that is possible in sprintf itself.</p>