in reply to Aligning Text

If you're wanting the lineup in your example, this code works:

#!/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]; }
giving this output:

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
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.