From 46ebaf2d318d6ce390b6afd47f69ca7271e7ae80 Mon Sep 17 00:00:00 2001 From: Ben Ostrowsky Date: Tue, 6 Apr 2010 14:31:16 +0000 Subject: [PATCH] Moving DBF-to-TSV utility (not Athena-specific) --- athena/athena-dbf-to-tsv.pl | 44 ------------------------------------------- dbf-to-tsv.pl | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 44 deletions(-) delete mode 100755 athena/athena-dbf-to-tsv.pl create mode 100755 dbf-to-tsv.pl diff --git a/athena/athena-dbf-to-tsv.pl b/athena/athena-dbf-to-tsv.pl deleted file mode 100755 index 3455d4c..0000000 --- a/athena/athena-dbf-to-tsv.pl +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use XBase; # or could use DBI and DBD::XBase; -use Data::Dumper; -use Getopt::Long; -use Encode; - -my $in = ''; -my $out = ''; -GetOptions('in=s' => \$in, 'out=s' => \$out); - -open OUT, ">$out" or die $!; - -my $table = new XBase $in or die XBase->errstr; - -# get list of field names -my @names = $table->field_names; - -# dump PATRONID, SURNAME, FIRSTNAME -print OUT join ("\t", @names) . "\n"; - -sub clean { - if ( $_ ) { - s/\\/\\\\/g; - s/\n/\\n/g; - s/\r/\\r/g; - s/\t/\\t/g; - Encode::encode("utf8", $_) - } else { ''; } # to avoid 'Use of uninitialized value in join' -} - -my $i = 0; -for (0 .. $table->last_record) { - $i++; - my ($deleted, @row) = $table->get_record($_); - @row = map (&clean, @row); - print OUT join("\t", @row) . "\n" unless $deleted; - -} - -print STDERR "$i records exported to $out.\n"; diff --git a/dbf-to-tsv.pl b/dbf-to-tsv.pl new file mode 100755 index 0000000..3455d4c --- /dev/null +++ b/dbf-to-tsv.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use XBase; # or could use DBI and DBD::XBase; +use Data::Dumper; +use Getopt::Long; +use Encode; + +my $in = ''; +my $out = ''; +GetOptions('in=s' => \$in, 'out=s' => \$out); + +open OUT, ">$out" or die $!; + +my $table = new XBase $in or die XBase->errstr; + +# get list of field names +my @names = $table->field_names; + +# dump PATRONID, SURNAME, FIRSTNAME +print OUT join ("\t", @names) . "\n"; + +sub clean { + if ( $_ ) { + s/\\/\\\\/g; + s/\n/\\n/g; + s/\r/\\r/g; + s/\t/\\t/g; + Encode::encode("utf8", $_) + } else { ''; } # to avoid 'Use of uninitialized value in join' +} + +my $i = 0; +for (0 .. $table->last_record) { + $i++; + my ($deleted, @row) = $table->get_record($_); + @row = map (&clean, @row); + print OUT join("\t", @row) . "\n" unless $deleted; + +} + +print STDERR "$i records exported to $out.\n"; -- 1.7.2.5