formating array file output using perl

Hello,

I am trying to output the values in an array to a file. The output needs to be formated such that each array value is left jusified in a field 8 character spaces long. Also, no more than 6 fields on a line. For example:

@array= 1..14;

Needs to be output to the file like so:

1       2       3       4       5       6
7       8       9       10      11      12
13      14

Of course, the amount of array values will vary.
Can't this be done with the printf function?

Please Help,
seismic_willy

Well, here's a while command that uses printf to output a unix array, and it closes out the line after every 6th entry:

#!/bin/ksh

a[1]=this
a[2]=array
a[3]=is
a[4]=holding
a[5]=nine
a[6]=entries
a[7]=right
a[8]=now
a[9]=.

i=1
w=0
while [ "${a[$i]}" ]
do
if [ $w -eq 6 ] ; then
   printf "\n"
   w=0
fi
printf "%-8s" ${a[$i]}
((i=i+1))
((w=w+1))
done

printf "\n"
exit 0

Hey thanks for that question and i got my answer also

seq 1 14 | xargs -n 6
#!/usr/bin/perl
my @num = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
for my $i (0 .. $#num) {
    printf ("%-8d", $num[$i]);
    print "\n" if (($i + 1) % 6 == 0);
}