#!/usr/bin/perl -w # # dbcolcreate # Copyright (C) 1991-1998 by John Heidemann # $Id: dbcolcreate,v 1.20 2003/05/23 04:17:07 johnh Exp $ # # This program is distributed under terms of the GNU general # public license, version 2. See the file COPYING # in $dblibdir for details. # sub usage { print STDERR <getopt) { $ch = $dbopts->opt; if ($ch eq 'd') { $debug++; } else { &usage; }; }; # Must be even number of args. &usage if ($#ARGV == -1 || $#ARGV % 2 != 1); %newcols = @ARGV; # Remember names in order. foreach (0..$#ARGV) { push(@newcols, $ARGV[$_]) if ($_ % 2 == 0); }; &readprocess_header; # # Don't recreate columns that already exist. # foreach (@newcols) { die "$prog: pre-existing column $_.\n" if (defined($colnametonum{$_})); }; # # Create new columns. # foreach (@newcols) { $col_f{$_} = &col_create($_); $code .= '$f[' . $col_f{$_} . "] = '" . $newcols{$_} . "';\n"; }; print STDERR $code if ($debug); # # Pass through data w/ new values. # &write_header(); my($loop) = q[ while () { &pass_comments && next; &split_cols; ] . $code . q[ &write_cols; }; ]; eval $loop; $@ && die ("$prog: interal eval error ``$@''.\n"); print "# | $prog " . join(" ", @orig_argv) . "\n"; exit 0; if (0) { my $x; $x = $colnametonum{'foo'}; }