GotToBTru,

Thanks for the response. Yes the first case I did read about that. But whenever I tried using it my script would execute and then never stop... Weird, would not stop printing blank lines in my terminal? Don't know why. But you second case is interesting I'll have to take a look into that. Thanks again!


TomDLux,

Gotcha, thanks for the reply. Makes sense...



Thanks to everyone who responded.
Here is what I ended up doing:

my @colLength; sub calcMaxColumn { # $i will hold index locations of column lengths in the array @co +lLengths. my $i; # Loop through the array @AoA. And if the length of the current c +olumn is greater then the length of the # same column in the previous row then set the greater number equ +al to that location in @colLength. for (my $x = 0; $x <= $#AoA; $x++) { $i = 0; for (my $y = 0; $y <= 11; $y++) { if ($colLengths[$i] < length($AoA[$x][$y])) { $colLengths[$i] = length($AoA[$x][$y]); } $i++; } } }


So basically I created the sub routine above that calculates the longest length of the string in each column. Then I used what you guys showed me, to use a variable (in my case $colLength[]) to format the output.


And here is how I printed:
my $strLen = 0; for (my $x = 0; $x <= $#AoA; $x++) { #If the current line is an owner then there will only be 10 el +ements. if ($AoA[$x][0] eq 'OWNER') { $waitline = 10; } #ELSE the line is a user waiting and we should add the time wa +iting to the end of that line, 11 total elements. else { $waitline = 11; } for (my $y = 0; $y <= $waitline; $y++) { $strLen = $colLengths[$y]; printf OUTDATA "%-${strLen}s ", $AoA[$x][$y]; } print OUTDATA "\n"; }


It works great!!! Thanks again guys. your the bestest...

Thanks,
Matt

In reply to Re: Possible to use variable in printf statement? by mmartin
in thread Possible to use variable in printf statement? by mmartin

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.