giving this output:#!/bin/perl use warnings; use strict; package main; my @names = ('NameA', 'NameB', 'NameC','NameD' ); my @ages = (353, 32, 2356, 75); my @sizes = (44, 212, 32, 328); my @scores = (900, 128, 99, 1000); print "======================================="; print "=============================================\n"; print " Name Age "; print " Size Score\n"; print "======================================="; print "=============================================\n"; for ( my $i = 0; $i < scalar @names; $i++ ) { printf "%5s %4d ", $names[$i], $ages[$i]; printf " %4d %4d\n", $sizes[$i], $scores[$i]; }
And the code does show how you can align your output using printf. But you may have variable length @names and @ages and such, and this kind of hard coded solution doesn't work well with something you would use over and over again. A smarter solution would save you from using many many cut-and-paste variants of this over and over again.C:\Code>perl table.pl ====================================================================== +============== Name Age Size + Score ====================================================================== +============== NameA 353 44 900 NameB 32 212 128 NameC 2356 32 99 NameD 75 328 1000
In reply to Re: Aligning Text
by dwm042
in thread Aligning Text
by Dr.Avocado
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |