On Dec 19, 2003, at 12:04 PM, Bill Jastram wrote:

We're getting closer. But lets say the first name of the first field in the first row is 'Bill'. And the first name of the first field in the second row is 'Lanette'. This command will not compensate for the difference in the length of the two first names. So, the alignment of the second fields in each row will not be correct. And so on ...

Does this help you understand where I'm headed?

No sir, I'm afraid I don't:


perl -e '@names = (["Bill", "Gray"],["Lanette", "Jones"]); printf "%-20s %-20s\n", $$_[0], $$_[1] foreach @names'

Bill                 Gray
Lanette              Jones

The above DOES line up correctly, with a fixed width font.

If you need to adjust the size of the fields based on the names, you'll need to make two passes. First, find the longest lengths. Then print.

printf() is doing the right thing though, as you can see above.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to