> I am curious as to the ways in which one can interact with mdb-tools from
> within a perl script? I am not a strong programmer. I can use the system
> command from perl to start the command line utilities but can not pass it the
> required information. Does anyone have much experience of working with both
> MDB tools and perl?
We have used MDB tools from Perl to list the tables in an MDB (using
mdb-tables), and get all the records from a table (using mdb-export).
We either used backticks or open to read from those commands. A direct call
to the C functions (libmdb) would probably be a better long teram solution
(DBD::mdbtools would be even better).
Pseudo code for we're using looks like:
# returns an array of table names
sub list_tables
{
my($fileName) = @_;
my $cmd = "mdb-tables $fileName";
my $output = `$cmd`;
if( 0 != ($? >> 8) ) {
die "Error obtaining tables list [$cmd]: $output : \$!=>$! : \$?=>$?";
}
my @lines = split(/[\s\r\n]+/,$output);
return @lines;
}
# returns an array of arrayrefs (array of records)
sub get_records
{
my($fileName,$tableName) = @_;
my $cmd = "mdb-export -d'\t' -Q $fileName '$tableName' |;
my $fh;
unless( open( $fh, $cmd ) ) {
die "Error opening mdb read handle: $! : cmd: '$cmd'";
}
my @lines = <$fh>;
close $fh;
my @records;
foreach my $line ( @lines ) {
my @fields = split('\t',$line);
$fields[-1] =~ s/[\r\n]+//;
push @records, \@fields;
}
return @records;
}
--
------------------------------------------------------------------------------
Wisdom and Compassion are inseparable.
-- Christmas Humphreys
mo...@vo... http://www.voicenet.com/~mortis
------------------------------------------------------------------------------
|