#!/usr/bin/perl -s use strict; our ($fs,$f); $fs ||=":"; $f ||= 'term'; use encoding "utf8"; tabpp({format=>$f,fs=>$fs}); sub tabpp{ my %opt =(format => "term", fs=>":"); if(ref($_[0]) eq "HASH") {%opt = (%opt , %{shift(@_)}) } ; my ($f1)=@_; my ($c1,$rc1); my $e1 = <>; chomp $e1; my $n=0; for (split(/\s*$fs\s*/,$e1)){ $rc1->{$n} = $_; $c1->{$_} = $n++; } print "%enc utf8\n"; my $tup; while ($tup = <>){ chomp $tup; my @a=split(/\s*$fs\s*/,$tup); for (0..scalar @a -1){ next unless $a[$_]; print "$rc1->{$_}\t$a[$_]\n"; } print "\n"; } close F1; } __END__ =head1 NAME tabpp - pretty-print textual relational databases =head1 SYNOPSIS tabpp [-fs=#] [-f=term] tab1... > f =head1 DESCRIPTION =head1 FORMATS each input table: country:capital first line - name of the fields Portugal:Lisboa tuple 1 France:Paris tuple 2 Spain:Madrid tuple n Output in format term: country Portugal capital Lisboa country France capital Paris country Spain capital Madrid =head1 Options -fs='!' changes the field separator (default ":") -f=format choose the output format (default "term") =head1 AUTHOR J.Joao Almeida, jj@di.uminho.pt =head1 SEE ALSO perl(1). =cut