From: Nicolas Boisselier Date: Mon, 21 Mar 2016 20:11:26 +0000 (+0000) Subject: multi tables X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=91be2bfe48e32c0310a35d6d25d8f156f7d4c5bf;p=nb.git multi tables --- diff --git a/bin/dbq b/bin/dbq index ebfddc27..f19079ed 100755 --- a/bin/dbq +++ b/bin/dbq @@ -227,7 +227,6 @@ sub parse_debug { sub csv2txt { my $sep = shift; my $noheader = shift; - my @len = (); my @lines = (); my $l; @@ -246,13 +245,7 @@ sub csv2txt { my @F = split($sep,$_); for (my $i=0;$i<@F;$i++) { - #$F[$i] = '' unless defined $F[$i]; $F[$i] = Encode::decode_utf8($F[$i]); - - #$len[$i] = $l if @len and ( $l = length($F[$i]) ) >= $len[$i]; - $len[$i] = length($F[$i]) unless defined $len[$i]; - $len[$i] = $l if ( $l = length($F[$i]) ) >= $len[$i]; - #$len[$i] = (@len>0 and ( $l = length($F[$i]) ) >= $len[$i]) ? $l : length($F[$i]); } push @lines, [@F]; @@ -265,6 +258,17 @@ sub csv2txt { # binmode( STDOUT, "utf8:" ); + csv2txt_next: + + my @len = (); + for (@lines) { + my @F = @$_; + for (my $i=0;$i<@F;$i++) { + $len[$i] = length($F[$i]) unless defined $len[$i]; + $len[$i] = $l if ( $l = length($F[$i]) ) >= $len[$i]; + } + } +#die map { join(' | ',@$_)."\n" } @lines; my $i = 0; my $t = -1; my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); @@ -273,20 +277,23 @@ sub csv2txt { print $sep_line; + sub csv_end { + print $sep_line if $tot; + print "$tot Records\n"; + } + while ($_ = shift @lines) { - #warn $format,scalar(@$_); - #warn ">>$format: ".$_->[0]; - #warn "<<$format>>"; - #next unless @$_; + if ($_->[0] =~ s/^\r// and $i) { + csv_end(); + print "\n"; + push @lines,$_; + goto csv2txt_next; + } printf $format,@$_; - #printf("%s\n",join(' ',@$_)); print $sep_line if !$noheader and !$i++; } - print $sep_line if $tot; - print "$tot Records\n"; - #close STDOUT; close STDERR; - #close STDIN; + csv_end(); exit; }