Please put <code> tags around your code, so we can read it. See Markup in the Monastery. I will attempt to make some sense of it anyway.

I am looking to right justify ONLY the totalQty field in below script.

print CUSTORDS "$sku$company$division$corp$sold$dept$shipTo$totalQty$space$poNum$customer$remarks$orderStatus$startDate\n"; totalQty = $totalQty . ($space x (8 - length($totalQty)));

I think you mean you want $totalQty to have the leading spaces in front of its value instead of behind, like " 42" instead of "42 ", right? The least invasive way to do this would simply be to flip the order of the concatenation:

totalQty = ($space x (8 - length($totalQty))) . $totalQty;

Now the longer answer...

How exactly do you want your output to look? Can you give us some sample input? It would be really helpful if your source code actually demonstrated your question in a way we could run. $sth->fetchrow_array isn't much use to those of us that aren't already connected to and familiar with your database. See How do I post a question effectively?.

$linestatus = $row[0]; $style = row[1]; . .

This can be greatly shortened with something like:

my ($lineStatus, $style, $colorCode) = @row;
$company = $space x 3;

Those lines seem very odd to me. Are you trying to blank out certain fields?

Given this, and your question of how to "right justify" the $totalQty field, it seems printf is what you need.

my $sku = $style . $colorCode; # Remove the $space x ?? padding printf CUSTORDS "%-32s%-3s%-8s%-12s%-8s%-3s%-12s%8s...\n", $sku, '', '', '', '', '', '', $totalQty;

Notice how all of the string formats have a '-' in front of the length, except for the last one, %8s, which corresponds to the $totalQty. That will cause all of the strings to be left-justified, except for $totalQty, which will be right justified.


Also, please use warnings; use strict; in your scripts, and maybe use diagnostics; -- these pragmas will flag a lot of errors before they become bugs.

Edit: Added some <hr/>s to stop my ideas from running together.


In reply to Re: right justify by rjt
in thread right justify by brpower

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.