my @fields = my ( $cat, $schem, $tn, $cn, $dt, $tyn, $cs, $bl, $dd, $npr, $nul) = $sth->fetchrow_array() my $num_fields = @fields; #0-indexed number of fields, ie 10 if there are 11 fields. $field_index = 0; while ( $cat, $schem, $tn, $cn, $dt, $tyn, $cs, $bl, $dd, $npr, $nul ) { print "\t$cn "; if (($tyn eq 'DATETIME') || ($tyn eq 'DOUBLE')) { print "$tyn"; } else { print "$tyn($cs)"; } print " not null" if ($nul == 0); # need to put a condition on adding the comma to not add the comma on the last loop. if ( $field_index < $num_fields) { print ",\n"; } $field_index++; }