printf and variable length?

D

Daemonice

Hello,

I am using the below statement. It writes exactly 19 positions,
padding the right of the string with spaces if need be.

printf DB "%-19s",$value;

However, now I need to write $fieldlength positions. I cannot find how
I can combine printf with $fieldlength. Is this possible, or should I
first format my string and then print it? What is the most ecomical
way to do this?

TIA,
Daemonice.
 
T

Tad McClellan

Daemonice said:
printf DB "%-19s",$value;

However, now I need to write $fieldlength positions. I cannot find how
I can combine printf with $fieldlength.


You can disambiguate the name of the variable with curly braces
(so that the "s" is not part of the variable name):

printf DB "%-${fieldlength}s", $value;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top