P
Perl Learner
I am having trouble printing a table of values.
The problem is that the table may contain anything from 2 character
strings
to signed numbers with 6 digits after the decimal.
i am unable to align them properly.
i tried using the following
printf "%3.9s", $variable
printf "%3.9f", $variable
the later serves the purpose for floating point numbers. the former
does somewhat what i want it to do .. it includes spaces before to fill
it up.
i didnt know what i was doing so i kept guessing the syntax and came up
with the above.
what i would like it to do is
if this is the max length (shown in X) ..
XXXXXXXXX
OB
-123.4
123.23453
1.2345235
0.1231355
0
see how the above is neatly aligned? .. it would be great if there is a
way i could align it like that.
in the example above, i showed "OB" centered and the numbers aligned to
the right.. but i dont mind if all are centered or all are aligned to
the right as long as they're all under those "XXXXXXXXX"s
is there a way to do that with these %s and printfs ?
thanks
The problem is that the table may contain anything from 2 character
strings
to signed numbers with 6 digits after the decimal.
i am unable to align them properly.
i tried using the following
printf "%3.9s", $variable
printf "%3.9f", $variable
the later serves the purpose for floating point numbers. the former
does somewhat what i want it to do .. it includes spaces before to fill
it up.
i didnt know what i was doing so i kept guessing the syntax and came up
with the above.
what i would like it to do is
if this is the max length (shown in X) ..
XXXXXXXXX
OB
-123.4
123.23453
1.2345235
0.1231355
0
see how the above is neatly aligned? .. it would be great if there is a
way i could align it like that.
in the example above, i showed "OB" centered and the numbers aligned to
the right.. but i dont mind if all are centered or all are aligned to
the right as long as they're all under those "XXXXXXXXX"s
is there a way to do that with these %s and printfs ?
thanks