I'm trying to use perl's printf function to get my output formatted correctly, but I'm having some trouble. Below is my practice printf.
printf ("'%-5'\n", 1234567);

It's giving me an invalid conversion error.

What would be the correct printf statement to line up output that will look like this.

ID IP PORT 1 192.168.1.1 10001 2 192.168.1.2 10001 3 192.168.1.3 10001 10 192.168.1.10 10001 150 192.168.1.150 10001

My output needs to line up even when the ID digits become double and triple digits (ie 10, 100). Using print, it moves everything over one space when the number of digits in ID increases. I've been reading about printf documentation but apparently I don't understand it. I also am unsure of how to output IP address with printf (floating points with multiple decimals). I'm more used to C++ <iomanip> header where you can just say setw(5) and left and you're done. Any help would be appreciated.


In reply to Help formatting with printf by cspctec

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.