If you're wanting the lineup in your example, this code works:

#!/bin/perl use warnings; use strict; package main; my @names = ('NameA', 'NameB', 'NameC','NameD' ); my @ages = (353, 32, 2356, 75); my @sizes = (44, 212, 32, 328); my @scores = (900, 128, 99, 1000); print "======================================="; print "=============================================\n"; print " Name Age "; print " Size Score\n"; print "======================================="; print "=============================================\n"; for ( my $i = 0; $i < scalar @names; $i++ ) { printf "%5s %4d ", $names[$i], $ages[$i]; printf " %4d %4d\n", $sizes[$i], $scores[$i]; }
giving this output:

C:\Code>perl table.pl ====================================================================== +============== Name Age Size + Score ====================================================================== +============== NameA 353 44 900 NameB 32 212 128 NameC 2356 32 99 NameD 75 328 1000
And the code does show how you can align your output using printf. But you may have variable length @names and @ages and such, and this kind of hard coded solution doesn't work well with something you would use over and over again. A smarter solution would save you from using many many cut-and-paste variants of this over and over again.

In reply to Re: Aligning Text by dwm042
in thread Aligning Text by Dr.Avocado

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.