• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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   "
1 Solution
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

rgbcofAuthor Commented:
You solved it.  Thank you.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now