[mapserver-users] XBase Question--adding columns to a .dbf file
klehr1 at tampabay.rr.com
klehr1 at tampabay.rr.com
Wed Oct 3 10:14:49 PDT 2001
I'd like to add two columns to a current .dbf file using the XBase perl module.
Could someone provide me a small piece of code to accomplish this task.
I'm not sure of the syntax for XBase to grab a row, chop it into its fields, add 2 more fields to the array, repack it into the xbase format then write it to a new .dbf (say ARGV[1]).
i.e. in plain text file say tab delimited
if (!$ARGV[1])
{
print "\n Invalid usage...Usage: add_columns.pl CURRENTFILE NEWFILE\n";
exit;
}
open(INPUT, $ARGV[0]) || die "Could not open $ARGV[0]";
open(OUTPUT, ">$ARGV[1]");
while(<INPUT>)
{
chomp();
@fields = split(/\t/, $_); # tab delimited data
$fields[$#fields + 1] = "new data element 1"; # add an element to the array
$fields[$#fields + 1] = "new data element 2"; # add another element
print "@fields\n";
$output_string = join "\t", @fields;
print OUTPUT "$output_string\n";
}
close(INPUT);
close(OUTPUT);
I'd like to do the same with .dbfs (append two columns to the current .dbf)
Thank you
Steve Lehr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20011003/bf89b029/attachment.htm>
More information about the MapServer-users
mailing list