I have a very simple perl script to convert a set of numbers into hex (converting dotted quad to hex). Here is the script:
#!/usr/bin/perl $octet1 = 10; $octet2 = 34; $octet3 = 2; $octet4 = 252; $hex1 = sprintf("%x", $octet1); $hex2 = sprintf("%x", $octet2); $hex3 = sprintf("%x", $octet3); $hex4 = sprintf("%x", $octet4); print "$hex1\n"; print "$hex2\n"; print "$hex3\n"; print "$hex4\n";
My output is this:
a 22 2 fc
How would you left justify/pad the values so that the desired output would be this?
0a 22 02 fc
This is an attempt to convert a dotted quad ip address from 10.34.2.252 to a hex value of 0a2202fc. If someone has a better suggestion on how to accomplish this, I'm all ears.

In reply to left justify/pad hex value by TheBigAmbulance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.