perl, how to populate a string with fix spaces

$fname = "James";
$lname = "Hill";
$status = "single";
# How to populate a string so that all the first name and last name line up.
# Assume I am using fix font.  Output would look like that.
"  James           Hill        single     "
"  Charles        Dancy    married   "
rgbcofAsked:
Who is Participating?
 
jeromeeConnect With a Mentor Commented:
Do you know the number of spaces you want or will it be based on the length of the first/last name on your list?
If you do know the spacing ahead of time. It's easy using printf as in:
 perl -e 'printf("%-12s %-20s %-10s\n", "James","Hill","single")'

Open in new window

0
 
rgbcofAuthor Commented:
You solved it.  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.